Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

virtual functions

Status
Not open for further replies.

werjocks

Programmer
Oct 27, 2003
24
0
0
US
I'm having a strange problem getting virtual functions to work... I get an "unresolved external symbol" error.
The virtual function is declaired and defined in the parent, and in one of the children it is overwritten.

If I simply move the overwritten function definition of the child into its header, I get no compilation problems.

I'm using Visual Studio 2003.

Any ideas?
 
Post some code and we'll see what we can find.
 
Sounds like the source file for the child isn't included in the project. Either that or you forgot the ClassName:: when implementing the function.
 
theres alot of code that was already working, but I'll include the relevent stuff....syntactically, I don't see anything missing...

//From parent header (ElectricComponent.h):
class ElectricComponent
{
public:
...
virtual void test();
...
};


//From parent (node.cpp):
#include "ElectricComponent.h"
...
void ElectricComponent::test()
{

}

//From child header (components.h):
#include "ElectricComponent.h"
class wire : public ElectricComponent
{
public:
...
void test();
...
};

//From child: (wire.cpp)
#include "components.h"
...
void wire::test()
{

}

//Errors produced:
OpenGL View Class error LNK2001: unresolved external symbol "public: virtual void __thiscall wire::test(void)" (?test@wire@@UAEXXZ)
OpenGL View Class error LNK2001: unresolved external symbol "public: virtual void __thiscall wire::test(void)" (?test@wire@@UAEXXZ)
OpenGL View Class fatal error LNK1120: 1 unresolved externals

if I just define the wire::test() as a part of the class definition in the header, no complaints. Could a syntax error somewhere else cause this kind of problem?
 
sorry guys, Im an idiot. Someone stuck a #ifdef in the middle of my file. None of the new functions were actually being compiled. Heres to stupidity at its finest.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top