Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: USB Pin
David Crow3-Apr-06 9:14
David Crow3-Apr-06 9:14 
AnswerRe: USB Pin
surfman193-Apr-06 11:23
surfman193-Apr-06 11:23 
AnswerRe: USB Pin
Ștefan-Mihai MOGA3-Apr-06 22:57
professionalȘtefan-Mihai MOGA3-Apr-06 22:57 
GeneralRe: USB Pin
surfman194-Apr-06 0:51
surfman194-Apr-06 0:51 
Questionreturn value of = operator Pin
Dr-Kuulun3-Apr-06 8:30
Dr-Kuulun3-Apr-06 8:30 
AnswerRe: return value of = operator Pin
David Crow3-Apr-06 8:34
David Crow3-Apr-06 8:34 
AnswerRe: return value of = operator Pin
includeh103-Apr-06 13:07
includeh103-Apr-06 13:07 
AnswerRe: return value of = operator Pin
Iain Clarke, Warrior Programmer3-Apr-06 13:53
Iain Clarke, Warrior Programmer3-Apr-06 13:53 
The reason is simpler than you may think. Its is so that you can make multiple assignment work efficiently.

You expect this to work:
int a, b, c;

a = b = c = 1;


So you also accept this to work:
CFwibble a, b, c;

c.DoSomethingtoInitialisethestruct;
a = b = c;


But the last line is equivalent to:
a = (b = c);


which means b = c has to be something you can assign to another struct / class / object of the same kind.

You could make the return value xyz, but that would mean creating a temporary copy on the stack, which is inefficient. The xyz & means a reference to b is passed, so no temporary copy is made.

For proper purity, you should also make the reference const, to prevent b from being messed about with...

class xyz
{
   ...
   const xyz &operator=(const xyz &rhs)
   {
      ...
      return *this;
   }
};


I hope that made sense for you!

Iain.



-- modified at 19:54 Monday 3rd April, 2006
GeneralRe: return value of = operator Pin
Ryan Binns3-Apr-06 18:43
Ryan Binns3-Apr-06 18:43 
GeneralRe: return value of = operator Pin
Dr-Kuulun4-Apr-06 0:14
Dr-Kuulun4-Apr-06 0:14 
QuestionSetting properties of ActiveX using Pin
Muhammad Azam3-Apr-06 8:08
Muhammad Azam3-Apr-06 8:08 
AnswerRe: Setting properties of ActiveX using Pin
Sheng Jiang 蒋晟3-Apr-06 13:20
Sheng Jiang 蒋晟3-Apr-06 13:20 
GeneralRe: Setting properties of ActiveX using Pin
Muhammad Azam3-Apr-06 23:53
Muhammad Azam3-Apr-06 23:53 
QuestionHow to handle single click and double click on list view? Pin
G Haranadh3-Apr-06 8:01
G Haranadh3-Apr-06 8:01 
AnswerRe: How to handle single click and double click on list view? Pin
ThatsAlok3-Apr-06 8:06
ThatsAlok3-Apr-06 8:06 
QuestionMultiple view updation Pin
Raghunandan S3-Apr-06 7:39
Raghunandan S3-Apr-06 7:39 
AnswerRe: Multiple view updation Pin
basementman3-Apr-06 7:49
basementman3-Apr-06 7:49 
QuestionCheckbox button question Pin
madmax00013-Apr-06 7:03
madmax00013-Apr-06 7:03 
QuestionRe: Checkbox button question Pin
David Crow3-Apr-06 7:08
David Crow3-Apr-06 7:08 
AnswerRe: Checkbox button question Pin
madmax00013-Apr-06 7:20
madmax00013-Apr-06 7:20 
GeneralRe: Checkbox button question Pin
David Crow3-Apr-06 7:39
David Crow3-Apr-06 7:39 
AnswerRe: Checkbox button question Pin
includeh103-Apr-06 7:17
includeh103-Apr-06 7:17 
QuestionIntegrating Visual C++ and Java Pin
pwimmers3-Apr-06 6:43
pwimmers3-Apr-06 6:43 
AnswerRe: Integrating Visual C++ and Java Pin
includeh103-Apr-06 6:48
includeh103-Apr-06 6:48 
QuestionAfxBeginThread Pin
viperlogic3-Apr-06 6:38
viperlogic3-Apr-06 6:38 

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.