c++ - 为什么从基类继承的成员函数未定义?
问题描述
我将编写一些类进行测试,例如以下文件。编译这些文件时出现一些错误:我通过派生类调用继承函数。但编译器这么说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;
}
解决方案
推荐阅读
- kubernetes - Hashicorp Vault Installation as part of Umbrella Helm Chart?
- git - How to remove files that are .gitignored with a recursive .../** pattern?
- asciidoctor - Prevent asciidoctor from doing ellipsis replacement in inline literal
- python - QST: error while using pickle to load the files
- css - Safari hyphenation bug
- django - DRF solving nested serializers circular import dependency
- python - Got AttributeError when attempting to get a value for field `phone_number` on serializer
- c# - How to make an asynchronous call on .NET Framework 4.0 without using Microsoft.Bcl.Async nuget package?
- javascript - MongoDB unset 删除子项中的所有内容
- sqlite - 从 Flutter App 将缩略图存储到 SqlLite