-2

What I want to do now is to make changements in FUNC.cpp and FUNC.h to inherit it to main.cpp and then, generate a diagram class at the end in which is really states that FUNC is inherited.

I want to make changements in my code, from namespace to classes, to allow the inheritance process.

I ' m having what is follow:

In a FUNC.h:

   namespace FUNC
{
    void f1(...);
    void f2(...);
}

In a FUNC.cpp

namespace FUNC
{

    void f1(...)
    {

    }

    void f2(...)
    {

    }

}

in test.cpp (which is meantime a class an having its test.h) , it's possible to call f1 and f2 as follow:

FUNC::f1(...);
FUNC::f2(...);
4

2 回答 2

1

如果您将命名空间更改为类,但仍想调用func1func2使用相同的语法(例如FUNC::func1()),则必须创建函数static

struct FUNC
{
    static void func1();
    static void func2();
};

如果你想func1在继承的类中覆盖,那么很简单:

struct FUNC2 : public FUNC
{
    static void func1();
};

然而,静态成员函数存在问题,因为它们无法轻松访问非静态成员。

于 2013-08-07T10:37:19.323 回答
0

我会回答我自己的问题

我必须在之后插入

class FUNC: public TEST
{
    static void func1();
    static void func2();
};
于 2013-08-07T11:49:35.280 回答