首页 > 解决方案 > 为什么从基类继承的成员函数未定义?

问题描述

我将编写一些类进行测试,例如以下文件。编译这些文件时出现一些错误:我通过派生类调用继承函数。但编译器这么说undefined reference to 'Base<someStruct>::func()'

我在尝试实际调用继承的成员函数时收到此错误。

基类和派生类在同一个文件中。为什么我会收到此错误?

//tool.h
template <class Addr>
struct Base {
...
public:
    bool func();
...
}

class Tool : public Base<struct someStruct> {
...
public:
    int func1();
...
}

以下是实现文件。

//tool.cpp
#include "tool.h"

template <class Addr>
bool Base<Addr>::func()
{
    ...
}

int Tool::func1()
{
}

main这里:

//test.c
#include "tool.h"

int main()
{
    Tool tool;

    tool.func();  //error is here;
}

标签: c++c++11

解决方案


推荐阅读