#include <iostream>
using namespace std;
class TT
{
friend class A;
public:
~TT() { cout << "Destroyed!!" << endl; }
int A() { return a; }
int B() { return b; }
int C() { return c; }
int D() { return d; }
private:
int a, b, c, d;
TT(int _a, int _b, int _c, int _d)
{ a = _a, b = _b, c = _c, d = _d; }
};
class A
{
public:
TT createTT(int a, int b, int c, int d) { return TT(a,b,c,d); }
void init_A()
{
TT item = getItemFromB();
cout << "TT item: " << item.A() << ", " << item.B() << ", "
<< item.C() << ", " << item.D() << endl;
}
virtual TT getItemFromB() = 0;
};
class B : public A
{
public:
virtual TT getItemFromB()
{ return createTT(1, 2, 3, 4); }
};
int main (int argc, char **argv)
{
B b;
b.init_A();
return 0;
}
#include <iostream>
using namespace std;
class TT
{
friend class A;
public:
~TT() { cout << "Destroyed!!" << endl; }
int A() { return a; }
int B() { return b; }
int C() { return c; }
int D() { return d; }
private:
int a, b, c, d;
TT(int _a, int _b, int _c, int _d)
{ a = _a, b = _b, c = _c, d = _d; }
};
class A
{
public:
TT createTT(int a, int b, int c, int d) { return TT(a,b,c,d); }
void init_A()
{
TT item = getItemFromB();
cout << "TT item: " << item.A() << ", " << item.B() << ", "
<< item.C() << ", " << item.D() << endl;
}
virtual TT getItemFromB() = 0;
};
class B : public A
{
public:
virtual TT getItemFromB()
{ return createTT(1, 2, 3, 4); }
};
int main (int argc, char **argv)
{
B b;
b.init_A();
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks