0

当我使用 GHS 多编译器构建和链接我的代码时,我遇到了一个问题。大致思路是这样的:

base.h -->

#ifndef base_h
#define base_h
class Base
{
    void basefncn1(); // defined in src file
    void basefncn2(); // defined in src file
    void basefncn3(); // defined in src file
}
#endif

接口.h -->

#ifndef interface_h
#define interface_h

#include "base.h"
class Interface : public Base
{
    void basefncn1();
}

#endif

派生类.h -->

#ifndef derived_h
#define derived_h

#include "base.h"
#include "interface.h"
class Derived : public Interface
{
    void basefncn1();
}

#endif

我得到的链接器错误是:

basefncn2() and basefncn3() is multiply defined -> Defined both in base.o and derived.o.

头文件受到保护。

我做错什么了吗?

编辑:我尝试更改 interface.h 文件。该函数现在在 interface.cpp 中定义。所以基本上, interface.h 和 derived.h 中没有定义函数。

4

0 回答 0