Click here to Skip to main content
15,913,055 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
Generaldependancies problem Pin
Mostafa Mohamed23-Oct-04 9:17
Mostafa Mohamed23-Oct-04 9:17 
GeneralRe: dependancies problem Pin
Anonymous2-Nov-04 19:19
Anonymous2-Nov-04 19:19 
GeneralReturning Strings in an arguement list Pin
nickOppen22-Oct-04 16:47
nickOppen22-Oct-04 16:47 
Questionwhat si #pragma once? Pin
Mario_Young22-Oct-04 13:01
Mario_Young22-Oct-04 13:01 
AnswerRe: what si #pragma once? Pin
Christian Graus25-Oct-04 12:50
protectorChristian Graus25-Oct-04 12:50 
GeneralRe: what si #pragma once? Pin
BlackDice27-Oct-04 7:54
BlackDice27-Oct-04 7:54 
Generalparser Pin
Anonymous21-Oct-04 9:18
Anonymous21-Oct-04 9:18 
GeneralOperator Overloading Problem Pin
Anonymous20-Oct-04 12:26
Anonymous20-Oct-04 12:26 
Dear all,

I cannot quite understand the logic behind the notion of operator overloading.
I understand that creating a class, is like creating a new type, therefore we can overload some operators to work with that new type. For example:
Ratio& Ratio::operator=(const Ratio& r)
{
num = r.num;
den = r.den;
return *this;
} This example is absolutely comprehensible but I cannot understand how I have to think, visualize the things in order to implement operator overloading in the *, *= operator, or in the == for instance.
Consider the Ratio class as the following:
class Ratio
{
friend Ratio& operator*(const Ratio& x, const Ratio y);
public:
Ratio(int =0, int =1);
Ratio& operator=(const Ratio&);

Ratio& operator*=(const Ratio&);
private:
int num, den;
};

Here is the understanding problem:
Ratio operator*(const Ratio& x, const Ratio& y)
{
Ratio z(x.num*y.num, x.den*y.den);
return z;
}
Is this the only way to overload that operator in this example? How one has to think in order to writew the above code? What are the steps involved in order to write the above two lines of code? And secondly in the first example (operator=) the return type is a reference to the Ratio but in the second is not a reference. Why is not a reference. When should we use a reference and when not?

Please bare in mind that I understand the use of friend functions.
Thanks in advance for the help,
grscot



GeneralRe: Operator Overloading Problem Pin
Christian Graus21-Oct-04 16:26
protectorChristian Graus21-Oct-04 16:26 
GeneralString to wchar_t conversion Pin
Murlai18-Oct-04 21:17
Murlai18-Oct-04 21:17 
GeneralRe: String to wchar_t conversion Pin
Mr Mayur K20-Oct-04 5:07
Mr Mayur K20-Oct-04 5:07 
GeneralString conversions Pin
Murlai18-Oct-04 19:51
Murlai18-Oct-04 19:51 
GeneralRe: String conversions Pin
George L. Jackson19-Oct-04 15:40
George L. Jackson19-Oct-04 15:40 
GeneralRe: String conversions Pin
AnsGe20-Oct-04 17:51
AnsGe20-Oct-04 17:51 
Generaliteration through map Pin
aspen_matthews18-Oct-04 19:44
aspen_matthews18-Oct-04 19:44 
GeneralRe: iteration through map Pin
Christian Graus19-Oct-04 9:28
protectorChristian Graus19-Oct-04 9:28 
GeneralRe: iteration through map Pin
aspen_matthews19-Oct-04 14:29
aspen_matthews19-Oct-04 14:29 
GeneralRe: iteration through map Pin
Christian Graus19-Oct-04 14:33
protectorChristian Graus19-Oct-04 14:33 
GeneralRe: iteration through map Pin
Mr Mayur K20-Oct-04 5:09
Mr Mayur K20-Oct-04 5:09 
GeneralRe: iteration through map Pin
aspen_matthews20-Oct-04 9:58
aspen_matthews20-Oct-04 9:58 
Generalplease help me its urgent Pin
youngashish18-Oct-04 18:38
youngashish18-Oct-04 18:38 
GeneralRe: please help me its urgent Pin
Christian Graus19-Oct-04 9:31
protectorChristian Graus19-Oct-04 9:31 
GeneralRe: please help me its urgent Pin
youngashish19-Oct-04 15:04
youngashish19-Oct-04 15:04 
GeneralRe: please help me its urgent Pin
Christian Graus19-Oct-04 15:08
protectorChristian Graus19-Oct-04 15:08 
GeneralCant intercommunicate between managed classes Pin
V5Dave18-Oct-04 9:43
V5Dave18-Oct-04 9:43 

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.