VS 2008 c++ code problem in friend funcation between diff classes

"cannot access private member declared in class"
its probelm related to friend function and i m use only one firend funcation and its run in vS2003 but not in VS 2008

class CP;
friend BOOL CIP::SDP(BOOL bDStaee);


CP,CIP both are class name class and SDP is Method which we want as friend.
=====================================================

pise of code :
we want CP class mthod SDP is friend of CIP class.



// first file

class CPI : public CWnd
{
public :
friend BOOL CIP::SDP(BOOL bDraftPrintState);
// THis line show the error
}

//another file

class CPI;

class CIP: public CSDChildWnd
{
private:
BOOL SDP(BOOL bDraftPrintState);
}
BOOL CIP::SDP(BOOL bDraftPrintState)
{
//CPI::sm_bDraftPrintState = bDraftPrintState;
return TRUE;
}
Why are you using friend on the class' member function?
becoze this is alrady open source code which run on vS2003 but not in VS2008 , we are migrate this things in to VS2008.
It's wrong.
ok you are right ,i think same
but this code is run in VS2003 so i put this Senario on forms
ok if u have any best Example for friend fun so let ke know.
i had read kanetkar Book its wirttern in both funcation declearation we need friend KEYWORD
its trate like a friend .

ok fine thanks youe reply
A member function already has access to class member data. This is what friendship provides.

If you're using friends, you should really stop and review your design. Nevertheless, here's an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class PersonMgr;

class Person
{
friend PersonMgr;

private:
        Person(int id);
        ~Person();

        Person(const Person&);
        Person& operator=(const Person&);

public:
        int     GetAge() const;
        void    SetAge(int);
        //...
};

class PersonMgr
{
public:
        PersonMgr(const char* dbinfo);

        Person* CreatePerson(int id);
        void DeletePerson(Person*);
};
Topic archived. No new replies allowed.