我有一个接口,我想创建一个header
带有函数的函数interface
和一个.cpp
实现这个头文件中的函数。但是当尝试这个时,我总是undefined reference to 'vtable for Test'
在Testt.h
文件中遇到问题。
我正在eclipse中做一个相当大的项目,所以我将我的问题减少到几个小类。
ITestAdapter.h:
#ifndef ITESTADAPTER_H_
#define ITESTADAPTER_H_
class TestAdapter {
public:
virtual int test() = 0;
};
#endif /* ITESTADAPTER_H_ */
测试.h:
#ifndef TESTT_H_
#define TESTT_H_
#include "ITestAdapter.h"
class Test: public TestAdapter{
public:
virtual int test();
};
#endif /* TESTT_H_ */
测试.cpp:
#include "Testt.h"
int test() {
return 0;
}
Test_main.cpp:
#include <iostream>
#include "Testt.h"
using namespace std;
int main() {
Test t;
int i = t.test();
cout << i << endl;
return 0;
}
如果我根本不使用Testt.h
并使用我的主要方法在文件中实现接口Testt.cpp
并包含Testt.cpp
(我想避免的),那么它可以正常工作。
Testt.cpp(修改):
#include "ITestAdapter.h"
class Test: public TestAdapter {
public:
int test() {
return 0;
}
};
所以我不明白为什么如果我使用标题(我认为这是更好的解决方案)它不起作用。
我希望我能清楚地解释我的问题是什么。如果没有请询问。