Jump to content
  • Advertisement
Sign in to follow this  
BloodLust666

friend class problems

This topic is 4837 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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!