More C++ stuff...

Started by
13 comments, last by ATC 11 years, 5 months ago

Hmmm... I've been clicking on the little code icon on the text editing toolbar (bottom row, farthest to the right -- to the right of the indent and alignment buttons). Is that not the right thing to be using?

To the left of the Quote icon is an icon that looks like “<>”. Use this.


I don't have to fully qualify other things, like my class/struct member methods, and I don't believe I've ever had this problem with free functions. What's the difference?

They were implicitly qualified by being inside “namespace ATCFramework { }”.

You have a class inside the ATCFramework namespace and declare an operator for it.
Inside the .CPP you start with “ATCFramework {” at the top, put all the class definitions next, and at the end you put “}”.
If those classes have operators it is not necessary to do this:

bool ATCFramework::MyClass::operator == ( etc. ) {
}


The ATCFramework:: part is implicit.

However your Point class is nested inside another class.
If you are still inside the “namespace ATCFramework { }” area you still don’t need to add the “ATCFramework::”, but you do need to add both classes:
bool MyClass::Point::operator == ( etc. ) {
}



L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

They were implicitly qualified by being inside “namespace ATCFramework { }”.

You have a class inside the ATCFramework namespace and declare an operator for it.
Inside the .CPP you start with “ATCFramework {” at the top, put all the class definitions next, and at the end you put “}”.
If those classes have operators it is not necessary to do this:

bool ATCFramework::MyClass::operator == ( etc. ) {
}


The ATCFramework:: part is implicit.

However your Point class is nested inside another class.
If you are still inside the “namespace ATCFramework { }” area you still don’t need to add the “ATCFramework::”, but you do need to add both classes:


Not sure if this changes anything but Point is not nested in another class... "Drawing" is actually a namespace nested in "ATCFramework".
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
Then you would have to do:
namespace ATCFramework {
namespace Drawing {

Point Point::operator + ( etc. ) {
}
}
}

If you want to avoid fully qualifying things.



L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


So it's only going to be useful if I catch the exception? Hmmm, that kinda sucks...

Er, yes, most C++ features are useful only if you use them. QED.

Did you think the language should require a dialog box with an OK button to be thrown up if you don't catch an exception? How's that going to work for the ARM chip controlling your automobile engine?

BTW, is the correct way to throw exception(...) or new exception(...)? I've been operating under the assumption that using throw new is like throwing type exception* which could be interpreted by the runtime as "throw unsigned long long" (or unsigned long in x86), since that's technically what a pointer is...
[/quote]
Throw by value, catch by const reference. Do not create exceptions on the free store.

The runtime interprets type pointer to ... as type pointer to ..., not as type unsigned long long. There are many architectures in which an address can not be stored in a data register (or vice-versa) so don't assume anything about convertability between unrelated types.. C++ is indeed a strongly-typed language: don't expect types to decay to unrelated types arbitrarily.

Stephen M. Webb
Professional Free Software Developer


Er, yes, most C++ features are useful only if you use them. QED.

Did you think the language should require a dialog box with an OK button to be thrown up if you don't catch an exception? How's that going to work for the ARM chip controlling your automobile engine?


That's not what I'm talking about... I do expect an error message to pop up when I'm debugging in my IDE. happy.png


Throw by value, catch by const reference. Do not create exceptions on the free store.

The runtime interprets type pointer to ... as type pointer to ..., not as type unsigned long long. There are many architectures in which an address can not be stored in a data register (or vice-versa) so don't assume anything about convertability between unrelated types.. C++ is indeed a strongly-typed language: don't expect types to decay to unrelated types arbitrarily.


Gotcha, thanks!
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________

This topic is closed to new replies.

Advertisement