Click here to Skip to main content
15,913,669 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionPlace Or Arrange pic1 in pic2 Pin
rahzani6-Jul-08 8:30
rahzani6-Jul-08 8:30 
AnswerRe: best arrange tiny pic in big pic Pin
David Crow6-Jul-08 10:31
David Crow6-Jul-08 10:31 
GeneralRe: best arrange tiny pic in big pic Pin
rahzani6-Jul-08 11:16
rahzani6-Jul-08 11:16 
GeneralRe: best arrange tiny pic in big pic Pin
Bram van Kampen6-Jul-08 11:42
Bram van Kampen6-Jul-08 11:42 
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 
I am having a difficult time understand what is really happening when I overload an operator for a class. Here is my class declaration. CC is short for CCarteseanCordinates.

class CC
{
public:
    CC(void);
    ~CC(void);

    CC operator+( CC &source );

    double Query_X();
    double Query_Y();
    double Query_Z();

    void Set_X( double value );
    void Set_Y( double value );
    void Set_Z( double value );

protected:
    double X;
    double Y;
    double Z;
};

Attempting to follow format of the example in the book I have, the definition of the + operator overload is:

1   CC CC::operator+( CC &source )
2   {
3    CC result = *this;
4    double sum = source.Query_X() + X;
5    result.Set_X( sum );
6//    repeat for Y
7//    repeat for Z
8    return result;
9   }; 

Line 3 starts with
CCarteseanCordinates result

Which seems to create a local object of type CCarteseanCordinates.

Now adding on the = *this;, the line now seems to say assign to that object the value of the local this pointer.

That is similar to writing
Int y;
Int *z = &y;
Int x = *y  

Except: The equal operator has not been overloaded so
Object1 = object2;

Is not a valid construct.

Should my declaration really be something like:
CC operator+( CC &source1, CC &source2 );

What is really going on here, and what should be going on?
Lets ignore the friend operator for the moment.

Thanks for your time

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 
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 

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.