Virtual overridden function must be implemented in header?
Lets say:
class A {
public:
virtual void foo() = 0;
};
class B : public A {
void foo();
}
Now MUST foo()'s implimentation for class 'B' be written in the header?
It seems I have having unresolved external symbols if I try to declare them in a source file.
Re: Virtual overridden function must be implemented in header?
It should work fine if you put something like
Code:
#include "b.h"
void B::foo() {
}
in a source file.
Re: Virtual overridden function must be implemented in header?
Yah I figure as much, I mean that is obvious. However VC8 is certainly complaining about it. foo() if its implimentation is in a source file I get an "unresolved external symbol". If I move I move the implimentation to the header then it compiles fine. This doesn't seem right... Having worked with Java so long I kinda got some of the finer rules mixed up...
Re: Virtual overridden function must be implemented in header?
Perhaps your project is incorrectly set up, and it doesn't include the separate .cpp file in the linking step?
Or the code that is not an example is actually a template class?