![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
Join Date: Mar 2005
Posts: 323
Rep Power: 4
![]() |
Re: Is there a better way to do this?
|
|
|
|
|
|
#12 |
|
hi: for(;;) goto hi;
|
Re: Is there a better way to do this?
Perhaps I worded it wrong. I was incorrect when I said classes couldn't (both can be return types) but structs can't be used with
<< due to lack of overloading. In your original post you said structures so I took it literally.edit: It appears I'm wrong again, apparently in C++ you can treat structs exactly like classes. Sorry for the trouble I'm causing!
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. Last edited by peaceofpi; Nov 25th, 2007 at 3:46 PM. |
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Is there a better way to do this?
The difference between a struct and a class is default access. This is one of several differences between C and C++ that people forget about when they say C++ is merely a superset of C.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#14 |
|
hi: for(;;) goto hi;
|
Re: Is there a better way to do this?
I still haven't touched on DaWei's suggestion (error checking), but here's the final code.
c++ Syntax (Toggle Plain Text)
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#15 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Is there a better way to do this?
Why won't you investigate error checking? You might be perfect, but your users are most assuredly not. Are you a God that that you can command obedience to your wishes without considering stupid responses? I might be wrong, but I think not.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#16 |
|
Not a user?
Join Date: Sep 2007
Posts: 307
Rep Power: 2
![]() |
Re: Is there a better way to do this?
|
|
|
|
|
|
#17 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Is there a better way to do this?
And how sure are you? Regardless of how sure you are, you are mistaken.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#18 | ||
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,186
Rep Power: 5
![]() |
Re: Is there a better way to do this?
Quote:
Quote:
struct is arguably a better thing to use in some situations.C++ classes, on the other hand, are like any other type in C++ in that they exist on the stack unless you explicitly allocate them on the heap (ie via the new operator, or equivalent).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
||
|
|
|
|
|
#19 |
|
hi: for(;;) goto hi;
|
Re: Is there a better way to do this?
DaWei, could you explain a little more about the error checking I should do? I'm open to suggestions, I just don't get what could go wrong (unless they passed a non-number to it).
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#20 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,186
Rep Power: 5
![]() |
Re: Is there a better way to do this?
Quote:
However, how do you handle conditions such as negative or greater than 360? If you're talking about motion, such as turning, then such conditions are to be expected, and should raise no concerns (though you need to decide which direction a negative measure represents). If you're talking about measurements of angles, such as the corner of a shape, then you're not going to have negatives or angles greater than 360; such parameters should be treated as errors.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|