What is promotion constructor? does it have any relation with copy constructor/assignment operator? I have seen one example however unable to understand that.
#include <iostream>
#include <vector>
using namespace std;
class base{
public:
base(){
cout << endl << "base class default construtor" << endl;
}
base(const base& ref1){
cout << endl << "base class copy constructor" << endl;
}
base(int) {
cout << endl << "base class promotion constructor" << endl;
}
};
class derived : public base{
public:
derived(){
cout << endl << "derived class default constructor" << endl;
}
derived(const derived& ref2){
cout << endl << "derived class copy constructor" << endl;
}
derived(int) {
cout << endl << "derived class promotion constructor" << endl;
}
};
int main(){
vector<base> vect;
vect.push_back(base(1));
vect.push_back(base(1));
vect.push_back(base(2));
return 0;
}
When I compile and execute: than the order has come like this:
base class promotion constructor
base class copy constructor
base class promotion constructor
base class promotion constructor
base class copy constructor
base class promotion constructor
base class promotion constructor
base class copy constructor
base class promotion constructor
Please help me to understand this concept of promotion constructor. I have searched on net however didn't get much info on this.
Thanks