Jump to content
  • Advertisement

Archived

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

PrettySneaky

Virtual functions + linking errors

This topic is 5244 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

I currently writing my first game and a problem has arisen. When i try to call a virtual function from my base class I get a linker error. This piece of code generate the same error. I use Visual Studio .NET...

class A
{
public:
   virtual void x();
   void test()
   {
      x();
   }
};

class B : public A
{
public :
   virtual void x()
   {
      cout << "B" << endl;
   }
};

[edited by - PrettySneaky on April 12, 2004 4:28:16 AM] [edited by - PrettySneaky on April 12, 2004 4:32:56 AM] [edited by - PrettySneaky on April 12, 2004 4:33:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
Post the error. Also, which of those functions have you actually provided bodies for?


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites

Sorry forgot to add the body to the x function i B. Fixed the first messge now..

the error mess was:

error LNK2001: unresolved external symbol "public: virtual void __thiscall A::x(void)"(?x@A@@..etc)

Share this post


Link to post
Share on other sites
If A::x() is virtual, you''ll need to either declare it pure virtual, or give it a body.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites

OK!! So now the code builds and compiles just fine. But during run-time i get this annoying Debug error message.

It says something like:

Debug error!

Program d:\....etc..

R6025
-pure virtual function call

Abort Retry Ignore

What''s going on??

Share this post


Link to post
Share on other sites
Sorry if i''m being insulting for asking this but you are trying to call the method from a base class pointer to a derived object aren''t you?

Also you didn''t cast the object to its base?

If you don''''t gosub a program loop you''''ll never get a sub-routine - Kryten Red Dwarf

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!