copy Assignment operator ?? Constructor ??

O

onkar

class Base{

// some stuff

};

int main(void){
Base a;
a=Base(10);
return 0;
}


what are the constructors called ?? Is copy assignment operator also
called in this situation ?? If yes how is it defined ??
 
J

James Kanze

class Base{

// some stuff

};
int main(void){
Base a;
a=Base(10);
return 0;

}
what are the constructors called ??

Default constructor in the first line of main. Constructor from
int in the second line of main.
Is copy assignment operator also
called in this situation ??

Obviously, since you have an assignment in the second line of
main.
If yes how is it defined ??

However you've defined it. By default, it calls the copy
assignment operator for each of the base classes, then the copy
assignment operator for each member.

If your C++ book doesn't explain this in detail, it's time to
change books.
 
K

karthikbalaguru

 class Base{

 // some stuff

};

int main(void){
        Base a;
        a=Base(10);
        return 0;

}

what are the constructors called ??

Default Constructor
Single argument Constructor
Is copy assignment operator also
called in this situation ??
Yes.

If yes how is it defined ??

Yes (you have done an assignment)

Karthik Balaguru
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top