K
kepeng
There are 2 abstract base classes:
class IB;
class IA
{
//...
public:
virtual IB* GetB() = 0;
}
class IB
{
//...
public:
virtual IA* GetA() = 0;
}
Then, this is derived classes:
class CB; //#1
class CA : public IA
{
//...
public:
CB* GetB(); //#2
}
class CB : public IB
{
//...
public:
CA* GetA(); //#3
}
The question is, the declaration do not work.
In C++, the overrided function can return a class which is public
derived from the return type of the function in base class.
When the function #2 returns IB*, it is OK. #3 is OK, too.
But, when #2 returns CB*, the compiler says something like "CB is not
derived from IB".
At #1, I can not declare like this:
class CB : public IB;
The syntax is not passed.
So, what can I do?
There is cycle dependence, but I do not care of the dependence: CA and
CB is almost in a single .cpp file.
class IB;
class IA
{
//...
public:
virtual IB* GetB() = 0;
}
class IB
{
//...
public:
virtual IA* GetA() = 0;
}
Then, this is derived classes:
class CB; //#1
class CA : public IA
{
//...
public:
CB* GetB(); //#2
}
class CB : public IB
{
//...
public:
CA* GetA(); //#3
}
The question is, the declaration do not work.
In C++, the overrided function can return a class which is public
derived from the return type of the function in base class.
When the function #2 returns IB*, it is OK. #3 is OK, too.
But, when #2 returns CB*, the compiler says something like "CB is not
derived from IB".
At #1, I can not declare like this:
class CB : public IB;
The syntax is not passed.
So, what can I do?
There is cycle dependence, but I do not care of the dependence: CA and
CB is almost in a single .cpp file.