constructor calls in vectors
Hello, good people.
I was thinking, is there a way to push to vector while calling a custom constructor?
1 2 3 4 5 6 7
|
class amm
{
public:
amm::amm(void);
amm::amm(int a, int b);
amm::~amm(void);
};
|
is it possible to call amm constructor with 2 parameters while pushing it into STL vector?
You mean take the constructor's arguments and put them into a vector?
Assuming it's a member vector:
1 2 3 4 5 6 7 8 9 10
|
class amm {
vector<int> intVect;
public:
amm::amm(void);
amm::amm(int a, int b) {
intVect.push_back(a);
intVect.push_back(b);
}
amm::~amm(void);
};
|
Last edited on
You shouldn't have the class scope specifier inside the class itself.
Is this what you are asking?
1 2 3 4 5 6 7 8 9 10
|
class amm
{
public:
amm(void);
amm(int a, int b);
~amm(void);
};
std::vector<amm> v;
v.push_back ( amm(1,2) );
|
Topic archived. No new replies allowed.