The point of this program was to create two objects of type classa and classb which take an address to each others locations and allow access using pointers. I tried spreading this idea across many files and there are many problems with errors. I assume my code is totally wrong but the concept should be possible to implement since I've done this already using a single file with namespaces.
This is the main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include "classa.h"
#include "classb.h"
usingnamespace std;
int main()
{
classa* a = new classa(99);
classb* b = new classb(0);
a.link(b);
b.link(a);
delete b;
delete a;
return 0;
}
since they booth have different names, the namespaces were not needed I think. Unless both classes were called class_clone but they one did something different than the other, then you would use a namespace. I'm not sure if thats what your implying anyway, my eyes went cross-eyed when I looked at the code, hope someone helps you out.
since they booth have different names, the namespaces were not needed I think. Unless both classes were called class_clone but they one did something different than the other,
Well, eventually classa and classb would have different methods so they aren't the same. This idea does work for a single file, let me know if you want me to post that. What I want are two separate files for each class since its easier to work with; but I guess if these are the problems I'm running into, it might be easier to stick to a single file and use that.
EDIT:: I created a single file program of what I want, how would I put this program into 2 header files for each class?
#ifndef CLASS_A
#define CLASS_A
#include "classb.h"
class b;
class a
{
private:
b* objb;
int data;
public:
void link(b* temp, int value);
int return_data();
};
void a::link(b* temp, int value)
{
objb = temp;
data = value;
}
int a::return_data()
{
return data;
}
#endif
#ifndef CLASS_B
#define CLASS_B
#include "classa.h"
class a;
class b
{
private:
a* obja;
int data;
public:
void link(a* temp, int value);
int return_data();
};
void b::link(a* temp, int value)
{
obja = temp;
data = value;
}
int b::return_data()
{
return data;
}
#endif