I have a interface and I want to create a header
with the functions from the interface
and a .cpp
implementing the functions in this header. But when try this I always get the problem undefined reference to 'vtable for Test'
in the Testt.h
file.
I'm working on a rather big project in eclipse so I reduced my problem to a few small classes.
ITestAdapter.h:
#ifndef ITESTADAPTER_H_
#define ITESTADAPTER_H_
class TestAdapter {
public:
virtual int test() = 0;
};
#endif /* ITESTADAPTER_H_ */
Testt.h:
#ifndef TESTT_H_
#define TESTT_H_
#include "ITestAdapter.h"
class Test: public TestAdapter{
public:
virtual int test();
};
#endif /* TESTT_H_ */
Testt.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;
}
If I don't use the Testt.h
at all and implement the interface within Testt.cpp
and include Testt.cpp
(what I want to avoid) within the file with my main-method then it works fine.
Testt.cpp (modified):
#include "ITestAdapter.h"
class Test: public TestAdapter {
public:
int test() {
return 0;
}
};
So I don't understand why it doesn't work if I use a header (which I think would be the nicer solution).
I hope I could explain clearly what my problem is. If not please ask.