Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > operator conversion

Reply
Thread Tools

operator conversion

 
 
John Cho
Guest
Posts: n/a
 
      03-03-2004
Class Cartesian
{ double x;
double y;
public:
Cartesian( ) { x = 0.0 ; y = 0.0;}
Cartesian(double x1, double y1)
{ x = x1; y = y1;}
};
class Polar
{ double radius;
double angle;
public:
Polar( ) { radius = 0.0; angle = 0.0;}
Polar(double r, double a) { radius = r; angle = a;}
//Use operator conversion function to convert Polar to Cartesian
operator Cartesian( )
{ double xx, yy;
xx = radius * cos(angle);
yy = radius * sin(angle);
return Cartesian(xx, yy);
}
};





why is Cartesian Cartesian(xx,yy); legal but float float(5.0); is not
legal


also why is it returning a constructor and not say

return (Cartesian Cartesian(xx, yy));

or
return (Cartesian C(xx, yy));

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-03-2004
* John Cho <(E-Mail Removed)> schriebt:
> Class Cartesian
> { double x;
> double y;
> public:
> Cartesian( ) { x = 0.0 ; y = 0.0;}


Style: use initializer lists.


> Cartesian(double x1, double y1)
> { x = x1; y = y1;}


Style: use initializer lists.


> };


Design: no way to use class Cartesian in any meaningful way.



> class Polar
> { double radius;
> double angle;
> public:
> Polar( ) { radius = 0.0; angle = 0.0;}


Style: use initializer lists.


> Polar(double r, double a) { radius = r; angle = a;}


Style: use initializer lists.


> //Use operator conversion function to convert Polar to Cartesian
> operator Cartesian( )


Should be 'const'.


> { double xx, yy;
> xx = radius * cos(angle);
> yy = radius * sin(angle);
> return Cartesian(xx, yy);
> }
> };



Design: no way to use class Polar in any meaningful way.



> why is Cartesian Cartesian(xx,yy); legal


It might be or not. If it is then it introduces a variable named
'Cartesian' of type 'Cartesian'. Which is absolutely not a good idea.


> but float float(5.0); is not legal


'float' is a reserved word and so cannot be used to name things.



> also why is it returning a constructor


Why is _what_ returning something?

But no matter what you're referring to, it's not possible to return
a constructor.

E.g., Polar:perator Cartesian() returns an object of type Cartesian,
where this object is constructed by a call to the Cartesian constructor.



> and not say
>
> return (Cartesian Cartesian(xx, yy));


Huh.



> or
> return (Cartesian C(xx, yy));


Huh.

 
Reply With Quote
 
 
 
 
John Cho
Guest
Posts: n/a
 
      03-03-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Alf P. Steinbach) wrote in news:40462599.396007500
@news.individual.net:


dude, why did you reply to my newsgroup message, i asked two specific
questions. why did you talk about style, then you did not even answer the
questions.

Damn dude, you just waste people's time doing that
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-03-2004
* John Cho <(E-Mail Removed)> schriebt:
> (E-Mail Removed) (Alf P. Steinbach) wrote in news:40462599.396007500
> @news.individual.net:
>
>
> why did you talk about style


Style is important in order to produce correct, maintainable and
efficient code.

In the code you presented all three concerns apply.


> then you did not even answer the questions.


I did.



> Damn dude, you just waste people's time doing that


Evidently I wasted my time, yes.

 
Reply With Quote
 
John Cho
Guest
Posts: n/a
 
      03-03-2004
your comments are not related to my question, i didn not ask about style
improvements okay. damn, email me in the future if you want to discuss off
topic of the messages i orignally post okay.

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-03-2004
* John Cho <(E-Mail Removed)> schriebt:
> your comments are not related to my question


What is your question?

The questions you posted were answered fully, to the extent possible.


> i didn not ask about style


You need to study that.

 
Reply With Quote
 
Leor Zolman
Guest
Posts: n/a
 
      03-03-2004
On Wed, 03 Mar 2004 18:56:35 GMT, John Cho <(E-Mail Removed)> wrote:

>your comments are not related to my question, i didn not ask about style
>improvements okay. damn, email me in the future if you want to discuss off
>topic of the messages i orignally post okay.


John,
Chill out a moment. If you spend a bit of time looking over other threads
in this and similar groups (comp.lang.c, alt.comp.lang.learn.c-c++, for
example), you'll see that posting code is tantamount to an open invitation
to have that code critiqued, and when folks like Alf contribute their time
to go over your code and point out all the stylistic (and often much more
than "just" stylistic) issues, you might want to take the opportunity to
learn from that rather than getting defensive.

The only question you asked that made any sense to /me/, he answered quite
well. The other question is so mired in fundamental misunderstanding of
what construction and operator conversion (?) are, that there's no way to
even tell what you were thinking when you asked the question. Thus, he
showed you things that /were/ clearly explainable.

No one's out to ride your butt, here, but if you can't handle constructive
feedback then I'd suggest you refrain from posting code.
-leor



Leor Zolman
BD Software
(E-Mail Removed)
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      03-03-2004
"Leor Zolman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> No one's out to ride your butt, here, but if you can't handle constructive
> feedback then I'd suggest you refrain from posting code.



#include <stdbitch.h>

voyeur mai_not()
{
return to_sender;
}

Sorry!

-Mike


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PSD to XHTML Conversion Services and PSD to HTML CSS ConversionServices, PSD to Joomla, Drupal, Wordpress Conversion PSD to XHTML Conversion Services and PSD to HTML CSS Conversion Services, PSD to Joomla, Drupal, Wor VHDL 0 04-25-2011 06:43 AM
operator << and conversion operator cronusf C++ 12 10-28-2010 09:21 AM
conversion operator and conversion ctor subramanian100in@yahoo.com, India C++ 2 09-15-2009 12:46 PM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
<complex> : no match for 'operator*' // conversion operator double() Arvid Requate C++ 2 06-23-2006 10:41 AM



Advertisments