Hi,
is it correct to use vector, for example, with no dynamically allocated objects?
Code:
#include <iostream>
#include <vector>
using namespace std;
class Mean{
public:
Mean(int a, int b){ mean = (a+b)/2.0; }
private:
float mean;
};
int main()
{
vector<Mean> means;
for(int i=0 ; i<5 ; i++){
means.push_back(Mean(i, i+1));
}
return 0;
}
I see a problem, correct me if I am wrong, you create two objects in the statment
Code:
means.push_back(Mean(i, i+1));
. The first is created to be passed to the function, and the second, the copy constructor is called.
Must I use pointers instead? Or this is good programming?
Thanks any insight.