Click here to Skip to main content
15,920,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: XOR mode Pin
Dominik Reichl16-Apr-03 1:58
Dominik Reichl16-Apr-03 1:58 
GeneralUnicode windows Pin
Hugo Hallman16-Apr-03 1:10
Hugo Hallman16-Apr-03 1:10 
GeneralRe: Unicode windows Pin
Anders Molin16-Apr-03 4:17
professionalAnders Molin16-Apr-03 4:17 
GeneralBest way to completely empty structure.. Pin
IrishSonic16-Apr-03 1:02
IrishSonic16-Apr-03 1:02 
GeneralRe: Best way to completely empty structure.. Pin
Dominik Reichl16-Apr-03 2:03
Dominik Reichl16-Apr-03 2:03 
GeneralRe: Best way to completely empty structure.. Pin
JT Anderson16-Apr-03 6:35
JT Anderson16-Apr-03 6:35 
GeneralRe: Best way to completely empty structure.. Pin
Gary R. Wheeler18-Apr-03 5:14
Gary R. Wheeler18-Apr-03 5:14 
GeneralWhich way is better to overload operator >> Pin
George215-Apr-03 23:50
George215-Apr-03 23:50 
Hi, everyone!


There are two operator >> overload functions in my class. And
both work OK. I have read some codes by others that the
function which overloading operator >> usually has two forms. One form
is returning null and another form is returning ostream&.

I want to know what is the difference between them. Which way is
better or in which case should I use the first form and vice versa.

Codes:

--------
#include <iostream>
#include <fstream>

using namespace std;

class A {

private:

int a;
public:

A (int a)
{
this->a = a;
}

operator << (ostream& os)
{
os << a;
}

ostream& operator << (ostream& os)
{
os << a;

return os;
}


};

int main()
{
A a(10);
ofstream f ("c:\\test.txt");
a << (f);

return 1;
}
--------


Thanks in advance,
George
GeneralRe: Which way is better to overload operator >> Pin
Joaquín M López Muñoz16-Apr-03 3:34
Joaquín M López Muñoz16-Apr-03 3:34 
GeneralRe: Which way is better to overload operator >> Pin
George216-Apr-03 3:43
George216-Apr-03 3:43 
Generallocale currency Pin
vcseeker15-Apr-03 21:57
vcseeker15-Apr-03 21:57 
GeneralRe: locale currency Pin
David Crow16-Apr-03 2:18
David Crow16-Apr-03 2:18 
GeneralIE toolbar disappearing buttons Pin
xenonii15-Apr-03 20:54
xenonii15-Apr-03 20:54 
GeneralRe: IE toolbar disappearing buttons Pin
xenonii16-Apr-03 2:22
xenonii16-Apr-03 2:22 
GeneralDDI hooking Pin
vikramlinux15-Apr-03 20:21
vikramlinux15-Apr-03 20:21 
GeneralRe: DDI hooking Pin
Dominik Reichl15-Apr-03 23:13
Dominik Reichl15-Apr-03 23:13 
GeneralRe: DDI hooking Pin
vikramlinux15-Apr-03 23:17
vikramlinux15-Apr-03 23:17 
GeneralTwo strange operations with this pointer. Pin
George215-Apr-03 17:18
George215-Apr-03 17:18 
GeneralRe: Two strange operations with this pointer. Pin
Michael Dunn15-Apr-03 19:36
sitebuilderMichael Dunn15-Apr-03 19:36 
GeneralRe: Two strange operations with this pointer. Pin
George215-Apr-03 19:55
George215-Apr-03 19:55 
GeneralRe: Two strange operations with this pointer. Pin
Michael Dunn15-Apr-03 20:10
sitebuilderMichael Dunn15-Apr-03 20:10 
GeneralRe: Two strange operations with this pointer. Pin
George215-Apr-03 20:11
George215-Apr-03 20:11 
QuestionWill this case cause memory leak? Pin
George215-Apr-03 16:15
George215-Apr-03 16:15 
AnswerRe: Will this case cause memory leak? Pin
Dave Bryant15-Apr-03 16:40
Dave Bryant15-Apr-03 16:40 
GeneralRe: Will this case cause memory leak? Pin
George215-Apr-03 16:53
George215-Apr-03 16:53 

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.