Click here to Skip to main content
15,904,817 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralID_WINDOW_TITLE_VERT Pin
MFC8-Dec-01 7:45
MFC8-Dec-01 7:45 
GeneralRe: ID_WINDOW_TITLE_VERT Pin
Michael Dunn8-Dec-01 9:22
sitebuilderMichael Dunn8-Dec-01 9:22 
QuestionFile compression...? Pin
BlackSmith8-Dec-01 5:49
BlackSmith8-Dec-01 5:49 
AnswerRe: File compression...? Pin
Henry Jacobs8-Dec-01 10:14
Henry Jacobs8-Dec-01 10:14 
Generaltaskbar icon... Pin
BlackSmith8-Dec-01 5:45
BlackSmith8-Dec-01 5:45 
GeneralRe: taskbar icon... Pin
Henry Jacobs8-Dec-01 10:10
Henry Jacobs8-Dec-01 10:10 
GeneralRe: taskbar icon... Pin
Chris Maunder8-Dec-01 15:50
cofounderChris Maunder8-Dec-01 15:50 
GeneralCArchive << operator Pin
Prateek Kaul8-Dec-01 2:55
Prateek Kaul8-Dec-01 2:55 
This is regarding a class called CArchive provided with MFC.

There are some overloaded operators "<<" and ">>" for inseration and
extraction in class CArchive.

One of them is:
friend CArchive& operator <<( CArchive& ar, const CObject* pOb );

The question is why the above operator is friend function???

The inseration and extration operators for the CObject class have been
defined as global friend functions whereas the same extraction and inseration
operators for basic data types such as int, float etc have been defined in
the CArchive class itself.

Why such a design? The CArchive class does not access any private or
protected memeber variables of the CObject class. Hence the query.
The source code is written as:

friend CArchive& operator<<(CArchive& ar, const CObject* pObj)
{
ar.WriteObject(pOb);
return ar;
}


and

CArchive::WriteObject()
{
/// .....lots of code but no private variable of CObject accessed
((CObject*)pOb)->Serialize(*this);
}

The is no accessing of private variables of CObject in any place.

Then why the << operator is a friend function??

I will be greatly obliged anyone could answer my query. Confused | :confused: Confused | :confused:

Prateek Kaul
Centre for Development of Advanced Computing (C-DAC),
Pune,India
GeneralIndustrial type programming Pin
Stan the man7-Dec-01 22:56
Stan the man7-Dec-01 22:56 
GeneralThread question Pin
Stan the man7-Dec-01 22:39
Stan the man7-Dec-01 22:39 
GeneralRe: Thread question Pin
Nish Nishant7-Dec-01 23:51
sitebuilderNish Nishant7-Dec-01 23:51 
GeneralMemory Pin
7-Dec-01 22:13
suss7-Dec-01 22:13 
GeneralRe: Memory Pin
Nish Nishant7-Dec-01 22:33
sitebuilderNish Nishant7-Dec-01 22:33 
QuestionCan I create a toolbar without framewnd? Pin
wormeye7-Dec-01 21:27
wormeye7-Dec-01 21:27 
AnswerRe: Can I create a toolbar without framewnd? Pin
Nish Nishant7-Dec-01 22:04
sitebuilderNish Nishant7-Dec-01 22:04 
GeneralRe: Can I create a toolbar without framewnd? Pin
wormeye8-Dec-01 17:21
wormeye8-Dec-01 17:21 
GeneralProblem with Popup Window ( Open in new window...OnNewWindow2 function ) Pin
7-Dec-01 19:24
suss7-Dec-01 19:24 
GeneralJust a couple of questions Pin
7-Dec-01 17:55
suss7-Dec-01 17:55 
GeneralRe: Just a couple of questions Pin
Nish Nishant7-Dec-01 18:36
sitebuilderNish Nishant7-Dec-01 18:36 
GeneralRe: Just a couple of questions Pin
Rick York7-Dec-01 19:44
mveRick York7-Dec-01 19:44 
GeneralRe: Just a couple of questions Pin
Nish Nishant7-Dec-01 19:55
sitebuilderNish Nishant7-Dec-01 19:55 
GeneralRe: CP script is messin up my code :-) Pin
Nish Nishant7-Dec-01 18:39
sitebuilderNish Nishant7-Dec-01 18:39 
GeneralRe: Just a couple of questions Pin
Christian Graus8-Dec-01 0:48
protectorChristian Graus8-Dec-01 0:48 
GeneralRe: Just a couple of questions Pin
Alvaro Mendez11-Dec-01 6:17
Alvaro Mendez11-Dec-01 6:17 
Generala question or 2 Pin
Cnoob7-Dec-01 16:34
Cnoob7-Dec-01 16:34 

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.