• Advertisement
Sign in to follow this  

friend class problems

This topic is 4714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Advertisement
This really belongs in For Beginners.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 once

class system {
friend class app;
int i;
};

// app.h ------------------------------------------
#pragma once

#include "system.h"

class app {
public:
void getsys( system &s ) {
s.i;
}
};

Share this post


Link to post
Share on other sites
You could make cSystem the base class for cApplication or declare a type of cSystem class in cApplication.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement