Click here to Skip to main content
15,893,814 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question"if ... enif" Question Pin
Programm3r8-Nov-06 22:02
Programm3r8-Nov-06 22:02 
AnswerRe: "if ... enif" Question Pin
Cedric Moonen8-Nov-06 22:09
Cedric Moonen8-Nov-06 22:09 
GeneralRe: "if ... enif" Question Pin
Programm3r8-Nov-06 22:21
Programm3r8-Nov-06 22:21 
AnswerRe: "if ... enif" Question Pin
ThatsAlok8-Nov-06 22:10
ThatsAlok8-Nov-06 22:10 
GeneralRe: "if ... enif" Question Pin
Programm3r8-Nov-06 22:23
Programm3r8-Nov-06 22:23 
AnswerRe: "if ... enif" Question Pin
fat_boy9-Nov-06 0:28
fat_boy9-Nov-06 0:28 
AnswerRe: "if ... enif" Question Pin
David Crow9-Nov-06 3:36
David Crow9-Nov-06 3:36 
Questionforward declare member function so that it can be friend function Pin
yccheok8-Nov-06 21:34
yccheok8-Nov-06 21:34 
currently, i have a private function in cat named privateFun.

i would like to have this function "private" to all except dog's action member function.

by using the following approach, all the dog's members can access all the cat's private members.

// cat.h
//
#ifndef CAT_H
#define CAT_H

// forward declaration.
class dog;

class cat
{
private:
friend class dog;
void privateFun() {}
};

#endif
//
// cat.h

// dog.h
//
#ifndef DOG_H
#define DOG_H

#include "cat.h"

class dog
{
private:
void action()
{
cat c;
c.privateFun();
}
};

#endif
//
// dog.h

however, i would like to have ONLY dog's action member function to access cat's private members.

i try the following approach but can't work.


// cat.h
//
#ifndef CAT_H
#define CAT_H

// forward declaration.
class dog;

class cat
{
private:
friend void dog::action(); /* HERE IS THE CHANGES AND COMPILATION ERROR HAPPENS HERE. */
void privateFun() {}
};

#endif
//
// cat.h

// dog.h
//
#ifndef DOG_H
#define DOG_H

#include "cat.h"

class dog
{
private:
void action()
{
cat c;
c.privateFun();
}
};

#endif
//
// dog.h

Of course, i would get the following compilation error:

c:\Documents and Settings\YC Cheok\Desktop\aaa\cat.h(10): error C2027: use of undefined type 'dog'

However, I just cann't include the dog header file into cat. This will introduce circular include problem.

Any advice? Can I have something like member function forward declaration? Thank you very much

AnswerRe: forward declare member function so that it can be friend function Pin
XtremDev8-Nov-06 22:26
XtremDev8-Nov-06 22:26 
QuestionHow can I programmatically add controls. Pin
Marko B.L.8-Nov-06 21:32
Marko B.L.8-Nov-06 21:32 
AnswerRe: How can I programmatically add controls. Pin
Mila0258-Nov-06 21:45
Mila0258-Nov-06 21:45 
GeneralRe: How can I programmatically add controls. Pin
ThatsAlok8-Nov-06 22:11
ThatsAlok8-Nov-06 22:11 
GeneralRe: How can I programmatically add controls. Pin
Mila0258-Nov-06 22:33
Mila0258-Nov-06 22:33 
GeneralRe: How can I programmatically add controls. Pin
Marko B.L.8-Nov-06 22:58
Marko B.L.8-Nov-06 22:58 
AnswerRe: How can I programmatically add controls. Pin
Mila0258-Nov-06 23:13
Mila0258-Nov-06 23:13 
GeneralRe: How can I programmatically add controls. Pin
Marko B.L.8-Nov-06 23:24
Marko B.L.8-Nov-06 23:24 
GeneralRe: How can I programmatically add controls. Pin
ThatsAlok9-Nov-06 0:25
ThatsAlok9-Nov-06 0:25 
Questionadding pause-resume options Pin
vijay_aroli8-Nov-06 21:18
vijay_aroli8-Nov-06 21:18 
AnswerRe: adding pause-resume options Pin
Rajesh R Subramanian8-Nov-06 23:30
professionalRajesh R Subramanian8-Nov-06 23:30 
GeneralRe: adding pause-resume options Pin
vijay_aroli8-Nov-06 23:50
vijay_aroli8-Nov-06 23:50 
QuestionPNG Resource to IPicture Pin
Parthi_Appu8-Nov-06 21:00
Parthi_Appu8-Nov-06 21:00 
QuestionHow to Create Hooks in Windows?? Pin
gloriousgopi8-Nov-06 20:01
gloriousgopi8-Nov-06 20:01 
QuestionLinker Error Pin
uday kiran janaswamy8-Nov-06 19:25
uday kiran janaswamy8-Nov-06 19:25 
AnswerRe: Linker Error Pin
sujtha8-Nov-06 21:16
sujtha8-Nov-06 21:16 
AnswerRe: Linker Error Pin
David Crow9-Nov-06 3:42
David Crow9-Nov-06 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.