←  Code Block

Fallout Studios Forums

»

Weird Visual Studio 2008 bug working with...

RaiDK's Photo RaiDK 25 Mar 2009

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.
Quote

CodeCat's Photo CodeCat 25 Mar 2009

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)?
Quote

RaiDK's Photo RaiDK 26 Mar 2009

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
Quote

CodeCat's Photo CodeCat 26 Mar 2009

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.
Quote