Hmm... No idea what that is. *googling*
I am sort of looking for that, I think... but, take this sample:
Code:
class A
{
private:
int a;
public:
int geta()
{
a = 1;
return a;
}
};
class B : virtual public A
{
private:
int b;
public:
int getb()
{
b = 2;
return b;
}
};
class C : virtual public A
{
private:
int c;
public:
int getc()
{
c = 3;
return c;
}
};
class D : public C, public B
{
};
int main()
{
D* d = new D();
cout << d->geta();
cout << d->getc();
cout << d->getb();
return 0;
}
But, I want to do the above code "snippet"; without the fourth class D...
Is that even possible? No ? Not without letting B go to C or C go to B?
Or I could add a pointer in either C or B, then create one object of the one with the pointer? hmm... trying!
Code:
#include <iostream>
using namespace std;
class A
{
private:
int a;
public:
int geta()
{
a = 1;
return a;
}
};
class B : virtual public A
{
private:
int b;
public:
int getb()
{
b = 2;
return b;
}
};
class C : virtual public A
{
private:
int c;
B* bpointer;
public:
C()
{
bpointer = new B();
}
void useB()
{
cout << bpointer->getb();
}
int getc()
{
c = 3;
return c;
}
};
int main()
{
C* d = new C();
cout << d->geta();
cout << d->getc();
d->useB();
return 0;
}
Both works the way I want to, but not the way I thought I could do it!
It became so messy with a pointer instead of a fourth class. Damn!
It would be cleaner if class A could contain both B and C... but thats not an option.
Any other ideas ?