UML representation for C/C++ function pointers

后端 未结 7 1285
梦谈多话
梦谈多话 2021-02-13 00:21

What would be the best representation of a C/C++ function pointer (fp) in an UML structural diagram?

I\'m thinking about using an interface element, may be even if \'deg

7条回答
  •  庸人自扰
    2021-02-13 00:48

    Defining of function pointers is out of scope of UML specification. What is more, it is language-specific feature that is not supported by many UML modeling software. So I think that the general answer to your first question suggests avoiding of this feature. Tricks you provided are relevant to Enterprise Architect only and are not compatible with other UML modeling tools. Here is how function pointers is supported in some other UML software:

    MagicDraw UML uses <<C++FunctionPtr>> stereotypes for FP class members and <<C++FunctionSignature>> for function prototype.

    Sample of code (taken from official site -- see "Modeling typedef and function pointer for C++ code generation" viewlet):

    class Pointer
    {
        void (f*) ( int i );
    }
    

    Corresponding UML model:

    Function pointers in MagicDraw UML

    Objecteering defines FP attributes with corresponding C++ TypeExpr note.

    Rational Software Architect from IBM doesn't support function pointers. User might add them to generated code in user-defined sections that are leaved untouched during code->UML and UML->code transformations.

提交回复
热议问题