From: sherlockmeister
this is basically what i was trying to achieve:
two classes that are able to use each other even though one is after the other,
actually the answer was easier than i thought.
what i was doing first:
class one{
void something(){
two t;
}
}
class two{
void something(){
one o;
}
}
you cant do this because class 'one' is not defined…however one can simply do this:
class one{
void something();
};
class two{
void something();
};
void one::something(){
two t;
}
void two::something(){
one o;
}
somethings you just take for granted in java…
So wait, if I am understanding this correctly there is data in one that you want in two and data in two that you want in one, correct? You might want to rethink your structure then and consider polymorphism and inheritance (IE a 3rd base class). So it looks something like this
#include <iostream>
using namespace std;
class base
{
protected:
int data;
public:
base()
{
data = 0;
}
virtual void function()
{
cout << "test" << data;
}
}
class one : public base
{
public:
one()
{
data = 1;
}
void function()
{
cout << "one" << data;
}
}
class two : public base
{
public:
two()
{
data = 2;
}
void function()
{
cout << "two " << data;
}
}
int main()
{
base* things[3];
thing[0] = new base;
thing[1] = new one;
thing[2] = new two;
for(int i = 0; i < 3; ++i)
{
things[i]->fucntion();
cout << endl;
delete things[i];
things[i] = null;
}
}
Give er a whiral to see polymorphism and inheritance in action.