Archived

This topic is now archived and is closed to further replies.

Problem with virtual in c++

This topic is 5742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

class Tetra { private: // const int startpostx =5; // const int startposy =19; int kleurR; int kleurG; int kleurB; protected: int mdraaing; int hdraaing; int ankerblokx; int ankerbloky; public: void Wentel(); Tetra(); virtual void Construeer();/*if i leave this line out i don't get the error*/ }; Tetra::Tetra() { ankerblokx=5; ankerbloky=19; hdraaing=0; //kleur moet ik random maken! kleurR=0; kleurG=0; kleurB=0; } void Tetra::Wentel() { hdraaing++; hdraaing%=mdraaing; // Construeer(); } class Vierkant:public Tetra { private: int x[4]; int y[4]; public: Vierkant(); void Construeer(); }; Vierkant::Vierkant() { mdraaing=1; x[0]=ankerblokx; y[0]=ankerbloky; } void Vierkant::Construeer() { //case is hier proforma switch(hdraaing) { case 0: x[1]=x[0]+1; x[2]=x[0]; x[3]=x[0]+1; y[1]=y[0]; y[2]=y[0]-1; y[3]=y[0]-1; break; } } /* this is the error i'm getting main.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Tetra::Construeer(void)" (?Construeer@Tetra@@UAEXXZ) Tetris___Win32_Debug/Tetris.exe : fatal error LNK1120: 1 unresolved externals */ Can anyone plz help me! :-) Edited by - Pilatus on March 23, 2002 3:08:23 PM

Share this post


Link to post
Share on other sites
You apparently want your constructueer method to be undefined in the base class. If this is so, then you won''t be able to make instances of your base class.

If the latter is what you want, then use the syntax "virtual void Constructueer() = 0" in the base class to make it pure virtual. Leave the derived class''s declaration and definition alone.

Another alternative would be to define constructueer in the base class.

--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."

Share this post


Link to post
Share on other sites
Try making
1. virtual void Construeer(); a pure virtual method:
virtual void Construeer() = 0;
Or
2. you''ll have to imlement this method for the baseclass Tetra, too. There should be this in your code:
...
void Tetra::Construeer()
{
...
}/


Decide on your own which is closer to your design, a pure virtual or just a virtual method.

Share this post


Link to post
Share on other sites