我要编写一些测试类,例如以下文件。
编译这些文件时出现一些错误:我通过派生类调用继承的函数。但是编译器说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;
}