Click here to Skip to main content
15,906,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe:arrange pic1 into pic2 Pin
rahzani6-Jul-08 11:19
rahzani6-Jul-08 11:19 
GeneralRe:arrange pic1 into pic2 Pin
Stephen Hewitt6-Jul-08 15:21
Stephen Hewitt6-Jul-08 15:21 
GeneralRe: best arrange tiny pic in big pic Pin
Stephen Hewitt6-Jul-08 16:37
Stephen Hewitt6-Jul-08 16:37 
QuestionBasic operator overloading Pin
bkelly136-Jul-08 8:21
bkelly136-Jul-08 8:21 
AnswerRe: Basic operator overloading Pin
Saurabh.Garg6-Jul-08 8:36
Saurabh.Garg6-Jul-08 8:36 
GeneralRe: Basic operator overloading Pin
bkelly136-Jul-08 12:43
bkelly136-Jul-08 12:43 
GeneralRe: Basic operator overloading Pin
Bram van Kampen6-Jul-08 13:11
Bram van Kampen6-Jul-08 13:11 
GeneralRe: Basic operator overloading Pin
bkelly136-Jul-08 16:01
bkelly136-Jul-08 16:01 
RE: So for CC class if you write a = b + c, where a, b, and c are objects of type CC, what it really means is a = b.operator+(c). Does this makes sense?

NO, it really does not make sense. The value being written is going into object a and the function should be called from the perspective of object a. To operate from the b perspective is counter-intuitive and just flat bad design. If we follow this up logically, a unary operation such as += should have one less argument, or zero arguments. However, that’s not my call so I had best learn to deal with it.

Regardless, lets see where this goes. The declaration looks like:
CC operator+( CC &source1 ); 

And the code looks like:
CC CC::operator+( CC &source1)
   {
    CC result = *this;
    double sum = source1.X + X;
    result.X = sum ;
//    repeat for Y
//    repeat for Z
    return result;
   };

And if I follow what your write, which is not certain, the code is executed from the perspective of object b. As I did not include the qualification “friend” in the declaration, code running from b does not have access to private variables in object a or in object c. That means that I should not have direct access to result.X or source1.X. So how can the compiler accept this code without error? It should force me to write:
double sum = X + source1.Get_X();
result.Set_X = sum;


in the first line, X is from the b object, source1.Get_X() gets the value from the c object, and in the third line result goes to the a object.

Given that the perspective is as you noted: a = b.operator+(c), why does the function have direct access to private members in objects a and c?

Although I have not yet figured this out, thank you for taking the time to respond.

Thanks for your time

GeneralRe: Basic operator overloading Pin
Saurabh.Garg6-Jul-08 17:51
Saurabh.Garg6-Jul-08 17:51 
GeneralRe: Basic operator overloading Pin
Saurabh.Garg6-Jul-08 18:05
Saurabh.Garg6-Jul-08 18:05 
AnswerRe: Basic operator overloading [modified] Pin
Luc Pattyn6-Jul-08 10:03
sitebuilderLuc Pattyn6-Jul-08 10:03 
GeneralRe: Basic operator overloading Pin
Graham Shanks6-Jul-08 10:37
Graham Shanks6-Jul-08 10:37 
GeneralRe: Basic operator overloading Pin
Luc Pattyn6-Jul-08 11:15
sitebuilderLuc Pattyn6-Jul-08 11:15 
AnswerRe: Basic operator overloading Pin
Dan6-Jul-08 12:54
Dan6-Jul-08 12:54 
GeneralRe: Basic operator overloading Pin
bkelly136-Jul-08 16:03
bkelly136-Jul-08 16:03 
QuestionHow to perform structured exception handling in Windows Vista Pin
V K 26-Jul-08 5:09
V K 26-Jul-08 5:09 
AnswerRe: How to perform structured exception handling in Windows Vista Pin
Stephen Hewitt6-Jul-08 15:37
Stephen Hewitt6-Jul-08 15:37 
GeneralRe: How to perform structured exception handling in Windows Vista Pin
V K 26-Jul-08 17:49
V K 26-Jul-08 17:49 
GeneralRe: How to perform structured exception handling in Windows Vista Pin
Saurabh.Garg6-Jul-08 18:08
Saurabh.Garg6-Jul-08 18:08 
GeneralRe: How to perform structured exception handling in Windows Vista Pin
Stephen Hewitt6-Jul-08 18:28
Stephen Hewitt6-Jul-08 18:28 
QuestionReplacement for IsBadReadPtr in Windows Vista Pin
V K 26-Jul-08 4:46
V K 26-Jul-08 4:46 
AnswerRe: Replacement for IsBadReadPtr in Windows Vista Pin
CPallini6-Jul-08 5:02
mveCPallini6-Jul-08 5:02 
GeneralRe: Replacement for IsBadReadPtr in Windows Vista Pin
V K 26-Jul-08 5:10
V K 26-Jul-08 5:10 
GeneralRe: Replacement for IsBadReadPtr in Windows Vista Pin
CPallini6-Jul-08 5:22
mveCPallini6-Jul-08 5:22 
GeneralRe: Replacement for IsBadReadPtr in Windows Vista Pin
Luc Pattyn6-Jul-08 11:35
sitebuilderLuc Pattyn6-Jul-08 11:35 

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.