Click to See Complete Forum and Search --> : VC2005 beta question


Kastet
November 1st, 2004, 06:03 PM
I have problem compiling a program Visual C++ 2005 Express beta which I seem to be unable to resolve myself. This code:

#include "stdafx.h"

using namespace System;

class A {
public:
virtual void printMessage();
};

class B: public A {
public:
void printMessage(){
Console::WriteLine(L"Hello from B!!!");
}
};

int _tmain()
{
Console::WriteLine(L"Hello World");

B b;
b.printMessage();

Console::ReadLine();
return 0;
}


Gives linking error:


Compiling...
Hello World.cpp
Linking...
Hello World.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall A::printMessage(void)" (?printMessage@A@@UAEXXZ)
C:\Documents and Settings\Ilya\My Documents\Visual Studio\Projects\Hello World.NET\Debug\Hello World.NET.exe : fatal error LNK1120: 1 unresolved externals


And I cannot find anything wrong :(

MrViggy
November 1st, 2004, 06:27 PM
You need to provide a body for the 'printMessage' function in class 'A'. Or, make it a pure virtual:
class A {
public:
virtual void printMessage() = 0;
};
Viggy

Kastet
November 1st, 2004, 06:56 PM
Thanks, I think this was the problem.