I do not understand why when I create a copy constructor and push it back into a vector, it calls the constructor more than once!
If I only do 1 push back, it will show the copy builder 1 time. if I do 2 push back it increases to 3.
I would also like to know why I can not use & in the builder! foo (foo & p) {}
#include <iostream>
#include <vector>
using namespace std;
class foo {
public :
foo(const foo& p){
cout<<"Construtor de Copia"<<endl;
}
foo () {
cout << "Chamando o Construtor " << endl ;
}
~ foo () {
cout << "Chamando o Destrutor " << endl ;
}
};
int main ( int argc , const char * argv []) {
vector < foo > v3 ;
foo f1;
v3.push_back(f1);
v3.push_back(f1);
return 0;
}