Hi everybody. I have a few questions that came up to my mind while looking at the cplusplus.com tutorials.
First, I have read that by default, all members of a class that are not specified as protected or public will be assumed by the compiler as private. I have looked at google C++ coding styles for an answer, but sadly I could not find one. So, can we assume that not explicitly stating that a block of members are private could be considered as a good/bad programming practice?
Second, while studying I also read that there is a default definition for the assignment operator (=) with the class itself as a parameter. This is supposed to copy the whole content of all data members of the objected passed as argument to the one at the left side. So for example, if I have a class point and a point object called my_point, with X,Y coordenates (4,5) and I declare another one called second_point and do the following assignation
second_point=my_point;
the second_point will also have the coordenates (4,5). So what is the differences between using the assignment operator and using a copy constructor such as:
1 2 3 4 5
|
point::point(const point& my_point)
{
x=my_point.x;
y=my_point.y;
}
|
to do identical copies of an object?
In a program that I am writting, I want to check if the given input for function SetX(double x_value) is in fact a valid input (any number). I have been looking all over the web for some sort of "isDouble" and "isInteger" or "isNumber" C++ function in order to narrow the possibilities of errors to the minimum, that being that the user has given a string as an input. Nontheless, I have not found an answer yet. I have looked at
http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/ to check the validity of inputs. However, these functions receive only integers as parameters (so, as far as I understand, the portability of the program could be compromised when using doubles as inputs). I have thought on another verification process, looking if the given input has characters different from '.', but that has not worked either. Can anyone give me a suggestion as to how to do the verification on this specific point?
thanks