473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

operator conversion

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

Jul 22 '05 #1
7 1527
* John Cho <jo*****@johncho.us> 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::operator 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.

Jul 22 '05 #2
al***@start.no (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
Jul 22 '05 #3
* John Cho <jo*****@johncho.us> schriebt:
al***@start.no (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.

Jul 22 '05 #4
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.

Jul 22 '05 #5
* John Cho <jo*****@johncho.us> 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.

Jul 22 '05 #6
On Wed, 03 Mar 2004 18:56:35 GMT, John Cho <jo*****@johncho.us> 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
le**@bdsoft.com
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
Jul 22 '05 #7
"Leor Zolman" <le**@bdsoft.com> wrote in message
news:i6********************************@4ax.com...
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
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents a rather good discussion of typecast operator overloading. I am presenting...
7
by: Richard Hayden | last post by:
Hi, I have the following code for example: /**********************************/ #include <iostream> class C1 { public:
6
by: c++newbie | last post by:
Hi all, I try to compile the following classes: main.cpp: #include <algorithm> #include <iostream> #include <fstream> #include <iterator>
4
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
5
by: Vijai Kalyan | last post by:
Hello, I have come back to C++ after a couple of years with Java so I am quite rusty and this question may seem poor: My platform is Windows XP with MSVC 7.1. I have a class with a...
6
by: Arne Schmitz | last post by:
I guess this has been asked before, but I cannot find any answer to this problem. I have program like this: ---SNIP--- #include <cassert> #include <cstdlib> class C { public:
2
by: linq936 | last post by:
Hi, I have this piece code, struct TriStr { MyString str1; MyString str2; MyString str3; TriStr(MyString s1, MyString s2, MyString s3){ this->str1 = s1;
15
by: Lighter | last post by:
In 5.3.3.4 of the standard, the standard provides that "The lvalue-to- rvalue(4.1), array-to-pointer(4.2),and function-to-pointer(4.3) standard conversions are not applied to the operand of...
4
by: abendstund | last post by:
Hi, I have the following code and trouble with ambiguity due to operator overloading.. The code is also at http://paste.nn-d.de/441 snip>>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.