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:
1 2
|
// Initialization:
int a = 123;
|
1 2 3
|
// Assignment
int a;
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.
Ardeshir81 wrote: |
---|
What about this piece of code : Name(new string(input)) |
I believe that is the initialization of the Name pointer with a new string object containing the input that you sent.
Ardeshir81 wrote: |
---|
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:
new Person;
uses the empty (default) constructor.
new Person("Someone");
uses the const char * constructor.
Ardeshir81 wrote: |
---|
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.