|
-
Feb 1st, 2006, 12:11 PM
#1
Thread Starter
PowerPoster
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.
Last edited by Halsafar; Feb 1st, 2006 at 04:19 PM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Feb 2nd, 2006, 08:04 AM
#2
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.
-
Feb 2nd, 2006, 02:57 PM
#3
Thread Starter
PowerPoster
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...
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Feb 2nd, 2006, 04:29 PM
#4
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?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|