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?
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).
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.
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.