friend class problems
I have 2 classes "cApplication" and "cSystem". i want ALL the functions and members available of cSystem publically to cApplication. i tried putting "friend class cSystem" in cApplication, but it keep saying that when i use a function from the cSystem class in a cApplication variable, it says undeclared identifier...
class cSystem
{
friend class cApplication;
};
cSystem has to declare who it's friends are. In your case, cApplication is making cSystem it's friend which is wrong.
{
friend class cApplication;
};
cSystem has to declare who it's friends are. In your case, cApplication is making cSystem it's friend which is wrong.
Did you include the cSystem header in the cApplication header?
// main.cpp ---------------------------------------#include "app.h"#include "system.h"int main() { system s; app a; a.getsys( s );}// system.h ---------------------------------------#pragma onceclass system { friend class app; int i;};// app.h ------------------------------------------#pragma once#include "system.h"class app { public: void getsys( system &s ) { s.i; }};
You could make cSystem the base class for cApplication or declare a type of cSystem class in cApplication.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement