friend class problems

Started by
6 comments, last by garyfletcher 19 years ago
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...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
This really belongs in For Beginners.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

ok? can anyone help?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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.
that doesn't work... it still says the same thing
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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;    }};
wow, that worked!! i didn't u had to do that, thanks
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
You could make cSystem the base class for cApplication or declare a type of cSystem class in cApplication.
Gary.Goodbye, and thanks for all the fish.

This topic is closed to new replies.

Advertisement