944,052 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3927
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 28th, 2005
0

OOp memory leak error

Expand Post »
When running the following code i get a big compile error:
Quote ...
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
[php]
#ifndef CLASS_H
#define CLASS_H

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

private:
int x;



};

#endif
[/php]

class functions saved as: debug.cpp
[php]
#include <iostream>

using namespace std;

#include "class.h"

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

int debug::getbug()
{
return x;
}
[/php]

main: saved as main.cpp

[php]
#include <iostream>

using namespace std;

#include "class.h"

int main()

{

debug d1(100);

return 0;
}
[/php]

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?
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 28th, 2005
0

Re: OOp memory leak error

Should it be like this?
debug::debug(int a)
{
   x = a;
}
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 28th, 2005
0

Re: OOp memory leak error

I made the corectiong but no different in the error I get.
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 28th, 2005
0

Re: OOp memory leak error

Is "debug.cpp" part of the project?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 28th, 2005
0

Re: OOp memory leak error

yes debug.cpp is the functions,
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 28th, 2005
0

Re: OOp memory leak error

Quote originally posted by Acidburn ...
yes debug.cpp is the functions,
I don't quite follow what you are saying. My question is whether or not the project includes both source modules (as opposed to the mere existance of files).

http://img97.exs.cx/img97/3200/untitled1ms.th.jpg
Last edited by Dave Sinkula; Mar 28th, 2005 at 2:59 pm. Reason: Added picture.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 28th, 2005
0

Re: OOp memory leak error

Now I'm confused I thought the header itself will include that cpp file, so when you include the .H files its auto included?
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 28th, 2005
0

Re: OOp memory leak error

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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Mar 28th, 2005
0

Re: OOp memory leak error

Quote ...
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
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Mar 28th, 2005
0

Re: OOp memory leak error

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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: The definiton of "Memory leaks"
Next Thread in C++ Forum Timeline: Clearing the screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC