The use of a colon after a constructor indicates initialization
. Whilst the body of a constructor is used for assignment
. One can interpret it like this:
int a = 123;
a = 123;
I think it's good practice to initialize as much as you can because later you need to maybe initialize references and const variables, and they can not be assigned.
|What about this piece of code : |
I believe that is the initialization of the Name pointer with a new string object containing the input that you sent.
|Is there a new method of calling new instead of doing this : |
Name = new string ; * Name = input;
I think they are equivalent, but I think that repetitive calls to new without deleting the object will cause a memory leak.
new string(/*constructor arguments*/);
is like creating an instance of your class with new:
uses the empty (default) constructor.
uses the const char * constructor.
|Looks like there are lots of Technics. The only thing I did was reading the tutorial on this site and some of reference part. What should I do to learn these thecnics? THNX!|
Google absolutely everything
! You'll get redirected to forums (StackOverflow especially) where there are a tonne of good answers.