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?

Should it be like this?

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

I made the corectiong but no different in the error I get.

Is "debug.cpp" part of the project?

yes debug.cpp is the functions,

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?

No.

::deep breath::

For multi-module coding, you need to have more than one module in the project. To do this you add files to the project.

Here. Go to Project->Add to Project->Files... and then add debug.cpp to your project. Then rebuild.

[edit]It ought to look like this.
[IMG]http://img30.exs.cx/img30/9715/untitled49ut.jpg[/IMG]
[/edit]

Bang and it works :S

what compiler you using?

>what compiler you using?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.