| | |
OOp memory leak error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
When running the following code i get a big compile error:
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?
•
•
•
•
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?
Should it be like this?
debug::debug(int a) { x = a; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
Originally Posted by Acidburn
yes debug.cpp is the functions,
http://img97.exs.cx/img97/3200/untitled1ms.th.jpg
Last edited by Dave Sinkula; Mar 28th, 2005 at 2:59 pm. Reason: Added picture.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
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.
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
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.
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.
[edit]And stop messing with the code. The error is not there.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Other Threads in the C++ Forum
- Previous Thread: The definiton of "Memory leaks"
- Next Thread: Clearing the screen
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






