Question 1: Yes. And yes. Well, I would never declare variables in that way.
Question 2: The colon after private and public is just to end the statement. Here it has no other use or meaning.
The : only means base classes follow at the start of class declaration. In constructor definitions is means the start of the initializer list, which can include the constructors of base classes and member variables. And then you've got the labels in switch statements, and the triad operator (e.g.
= (a < b) ? a : b
), ...
Question 3: Sphere (double radius); is fine
But it is better to use the initializer list in its implementation, eg.
1 2 3 4 5 6 7
|
Sphere::Sphere() : r(5.0) // the .0 makes it clearet that it's a double
{
}
Sphere::Sphere(double radius) : r(radius)
{
}
|
is better
Question 4: because that's the way it is!(?) (Hopefully someone who has a better grasp of parser theory can explain by it's needed here, and similarly for struct and enum declarations).
Andy
P.S. And things have got to be declared before use!
If your file is pasted as-is, I can see the class Sphere is declared after you first try to use it in main();
The implementation (or definition) of class Sphere can be provided after main, but not its declaration.
P.P.S. Also, please edit your above ost to yses tags: "How to use tags"
http://www.cplusplus.com/articles/z13hAqkS/