Sign in to follow this  
BloodLust666

friend class problems

Recommended Posts

BloodLust666    104
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
GamerSg    378
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
jflanglois    1020
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this