G
Gergely Korodi
Hello,
I have two classes, say A and B, defined in header files "A.hh" and
"B.hh," respectively. The definition of class B looks like
#ifndef _B_HH_
#define _B_HH_
#include "A.hh"
// other includes here
class B {
A a;
int f (/*lots of parameters*/);
};
#endif
I'd like B::f to be a friend of class A. Is it possible to do this? If
I write
#ifndef _A_HH_
#define _A_HH_
#include "B.hh"
class A {
friend int B::f (/*lots of parameters*/);
// some other stuff
};
the compiler complains when it gets to the "A a;" line included from
B.hh, saying class A is not defined there yet. Moreover, the parameters
of B::f are completely irrelevant to class A, so I would not like to
include the corresponding header files in A.hh just for them. Is there
any solution to tackle this?
Thanks,
Gergo
I have two classes, say A and B, defined in header files "A.hh" and
"B.hh," respectively. The definition of class B looks like
#ifndef _B_HH_
#define _B_HH_
#include "A.hh"
// other includes here
class B {
A a;
int f (/*lots of parameters*/);
};
#endif
I'd like B::f to be a friend of class A. Is it possible to do this? If
I write
#ifndef _A_HH_
#define _A_HH_
#include "B.hh"
class A {
friend int B::f (/*lots of parameters*/);
// some other stuff
};
the compiler complains when it gets to the "A a;" line included from
B.hh, saying class A is not defined there yet. Moreover, the parameters
of B::f are completely irrelevant to class A, so I would not like to
include the corresponding header files in A.hh just for them. Is there
any solution to tackle this?
Thanks,
Gergo