When running the following code i get a big compile error:

Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall debug::debug(int)" (??0debug@@QAE@H@Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Class definiation saved as : class.h

#ifndef CLASS_H
#define CLASS_H

class debug
{
public: 
   debug(int a = 77);
   int getbug();

private:
   int x;



};

#endif

class functions saved as: debug.cpp

#include <iostream>

using namespace std;

#include "class.h"

debug::debug(a)
{
 a = x;
}

int debug::getbug()
{
return x;
}

main: saved as main.cpp

#include <iostream>

using namespace std;

#include "class.h"

int main()

{

debug d1(100);

return 0;
}

if you've noticed in main thats theres an include.h , if I change it to include the .cpp instead it works 100% but thats not considered good programming. So I'm hoping someone will let me know whats what?

Now I'm confused I thought the header itself will include that cpp file, so when you include the .H files its auto included?

A header should have declarations and allow all modules to compile. But a definition is needed to successfully link. This is where you are having problems. You tell the linker to expect a definition to be found, but then don't tell it where to find it.

I'm not sure if you looked at the picture I added to my previous reply in the edit, but your project ought to look something like that.

main.obj : error LNK2001: unresolved external symbol "public: int __thiscall debug::getbug(void)" (?getbug@debug@@QAEHXZ)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall debug::debug(int)" (??0debug@@QAE@H@Z)
Debug/main.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

I made the edits but it also failed... I'm going to have a play with working code and see if that produces something different

This is between you and the linker. Look at the project pane. See the two modules listed.

[edit]And stop messing with the code. The error is not there.

So basically its my compiler? I have another code which works perfectly ... I ran that and it produced 7 liner errors, loaded up linux and built the objects and it compiles fine!! Does this mean that Microsoft VC++ is not ment for this task?

>what compiler you using?

Usually BC5.5 command line; sometimes MSVC6; sometimes Dev-C++. And ICCAVR for my current project.

This article has been dead for over six months. Start a new discussion instead.