Jump to content


Weird Visual Studio 2008 bug working with C++ Virtual methods


3 replies to this topic

#1 RaiDK

    I have an Energon Axe. Your argument is invalid.

  • Gold Member
  • 4107 posts

Posted 25 March 2009 - 04:57

Doing a uni assignment atm and getting a really weird bug:

Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall Student::DisplayInformation(void)" (?DisplayInformation@Student@@UAEXXZ) Student.obj Assignment 1 Remake

Error 2 error LNK2001: unresolved external symbol "public: virtual void __thiscall Student::DisplayAssessment(void)" (?DisplayAssessment@Student@@UAEXXZ) Student.obj Assignment 1 Remake


Guilty code is as following:

#include <iostream>
#include <string>
using namespace std;

class Student
{
public:
    Student();

*snip*

[b]    virtual void DisplayInformation();
    virtual void DisplayAssessment();[/b]
    
private:
*snip*
    
};


When I comment out the virtual functions it works fine though. No clue how to solve this one :D

Edited by RaiDK, 25 March 2009 - 05:08.

View PostMasonicon, on 17 Oct 2009, 13:44, said:

According to Conspiracy theories in internet, sci-fi and fantasy are real!

#2 CodeCat

    It's a trap!

  • Gold Member
  • 6111 posts

Posted 25 March 2009 - 14:46

Unresolved references mean that there are calls to a function, but the function itself isn't implemented anywhere. Are those functions actually defined in a .cpp file somewhere? If not, then perhaps you intended to make the functions abstract (pure virtual)?
CodeCat

Posted Image
Posted Image

Go dtiomsaítear do chód gan earráidí, is go gcríochnaítear do chláir go réidh. -Old Irish proverb

#3 RaiDK

    I have an Energon Axe. Your argument is invalid.

  • Gold Member
  • 4107 posts

Posted 26 March 2009 - 06:54

Ah yep, that was the problem... They weren't in the CPP file yet. I'd assumed the error was elsewhere since it compiled fine with regular methods not being in the CPP :-S

Thanks for your help, you knew more on the subject than the subject lecturer did :P

View PostMasonicon, on 17 Oct 2009, 13:44, said:

According to Conspiracy theories in internet, sci-fi and fantasy are real!

#4 CodeCat

    It's a trap!

  • Gold Member
  • 6111 posts

Posted 26 March 2009 - 14:48

Like I said, you only get undefined reference errors if there are actually references to a function. So as long as you don't call the function anywhere, there won't be an error if the function is not implemented. Perhaps that's what happened first time: You added a function call and this triggered the error.
CodeCat

Posted Image
Posted Image

Go dtiomsaítear do chód gan earráidí, is go gcríochnaítear do chláir go réidh. -Old Irish proverb



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users