A question about pointers

T

Tony Johansson

Hello Experts!

I have this statement
Student* john = michael;
where the pointer john is pointing to the same class object that michael is
pointing at.
But now to my question.will the copy constructor for the Student class be
called or any other constructor.

Many thanks.
//Tony
 
R

Rolf Magnus

Tony said:
Hello Experts!

I have this statement
Student* john = michael;
where the pointer john is pointing to the same class object that michael
is pointing at.
But now to my question.will the copy constructor for the Student class be
called or any other constructor.

No.
 
J

Jeremiah L.Jiang

Hello Tony:
The john's type is pointer(not Student) and points to a Student object.
It is nearly the same as int. Its value is an address. Therefore, the
Student's copy constructor will not called. If the code is as the
follow:
Student john = michael;//michael is a Student object. john's type is
Student,not pointer
the Student's copy constructor will be called.

Jeremiah L.Jiang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top