Hey there!
And so begins my trek into the world of C++! I have become quite fluent in Java and have begun to pick up C++, it's moving along quickly but certain things, mostly syntactical, are holding me up.
Here are a few things that are on my mind that perhaps someone could assist me in answering:
First:
Coming from the world of Java, the idea of 'null' is fresh within my mind... However, in C++'s world of pointers I'm finding that the concept of null is not so outright. So, my question is this, how does one check for nulls and how might they occur in C++? My understanding is that a null in C++ is a pointer that holds a value of zero. Is this correct?
Secondly:
Again, coming from Java, the term
new
is used to instantiate any object. Whereas, in C++ it is used to declare allocations for dynamic memory. I understand this much, however, I'd like to know of a good example in which one would use
new
effectively as opposed to making constant variables (if that's the right name for them, i.e.
string myString
not using the 'new' operator).
Thirdly:
I understand the concept of 'Friends' and how to declare them. But is this a common practice? Declaring objects to be friends outside of the same object type seems like a terrible excuse to couple classes.
Lastly:
Having just read the exceptions lesson on this site one key thing has come to my attention, that is, declaring the type of exception a function may throw. For example:
1 2 3
|
void toThrow() throw(int) {
throw 'a';
}
|
As far as I could gather from the guide the keyword
throw()
after the function identifier, in this case
throw(int)
, it is supposed to limit the type of exception that can be thrown? But in this case, when I run the program it allows me to catch the char exception that is thrown. Obviously I'm misunderstanding the concept of the throw() operator and if someone could better explain it to me I would be very grateful!
Thanks a ton for any and all responses, and my apologies if something I wrote here is incorrect (haven't gotten my C++ legs yet.)