J
Joseph Turian
I am having difficulty defining a friend function because of a #include
cycle:
============ obj.H ================
#ifndef _obj_
#define _obj_
#include "cont.H"
class cont;
class obj {
friend void cont::foo(obj& o);
private:
void called_by_foo();
};
#endif
============ cont.H ================
#ifndef _cont_
#define _cont_
#include "obj.H"
#include <vector>
class cont {
public:
void foo(obj& o);
private:
std::vector<obj> v;
};
#endif
============ cont.C ================
#include"cont.H"
from cont.C:1:
obj.H:9: error: member `void cont::foo(obj&)' declared as friend before
type `cont' defined
===============
How can I fix this such that cont can contain obj, but obj can have a
member function of cont as a friend function?
Thanks,
Joseph
cycle:
============ obj.H ================
#ifndef _obj_
#define _obj_
#include "cont.H"
class cont;
class obj {
friend void cont::foo(obj& o);
private:
void called_by_foo();
};
#endif
============ cont.H ================
#ifndef _cont_
#define _cont_
#include "obj.H"
#include <vector>
class cont {
public:
void foo(obj& o);
private:
std::vector<obj> v;
};
#endif
============ cont.C ================
#include"cont.H"
In file included from cont.H:4,gcc -o cont.o cont.C
from cont.C:1:
obj.H:9: error: member `void cont::foo(obj&)' declared as friend before
type `cont' defined
===============
How can I fix this such that cont can contain obj, but obj can have a
member function of cont as a friend function?
Thanks,
Joseph