Re: mutual class dependencies
Grizlyk wrote:
//forward declarations
class B;
class A;
class A
{
public:
A()
{
}
A& SetContext(B::TContext eContext)
You can pass eContext by reference
A& SetContext(B::TContext& eContext)
Well, looks like useless advice here, because B::TContext must be
declared. You can not declare B::TContext like this (i do not know
why)
class B;
//using B::C;
//class B::C;
but you can use template<> to delay declaration
template<typename T=B>
class A
{
public:
A& SetContext(T::TContext& eContext);
};
template<typename T> //(T=B is not allowed)
void ::foo(T::TContext& c)
{
A<T> a;
a.SetContext(c);
}
class B
{
public:
//can be declared only for references
class TContext;
};
void ::boo(B::TContext& c)
{
foo<B>(c);
}
or remove declaration of TContext into separated class
And yet, instead of using B::TContext& reference, you can move body of
SetContext function outside of class A scope and place the body after
B::TContext complete declaration, but the declaration of SetContext
with eContext passed by value will touch you in code like this
void ::foo(B::TContext& b)
{
A a;
a.SetContext(b);
}
if the code ::foo will be placed befor B::TContext complete
declaration.
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new