S
sidney
Hi all,
I am trying to make a vector containing objects the have a reference
member. However, as soon as I try to push_back an element into this
vector, g++ balks at the fact that it needs to instantiate an operator=
on the class containing the reference members (see below for what I try
to do).
#include <vector>
class TestClass {
private:
const int & m_q;
public:
TestClass(const int & q) { m_q = q; }
};
int main()
{
std::vector<TestClass> v;
int hello = 5;
v.push_back(TestClass(hello));
}
I would have expected that a copy constructor call would be executed in
the offended line instead of an assignment.
Can anyone explain how the desired operation could be implemented (or
why it doesn't make sense for me to want it to work?).
Best regards, Sidney
I am trying to make a vector containing objects the have a reference
member. However, as soon as I try to push_back an element into this
vector, g++ balks at the fact that it needs to instantiate an operator=
on the class containing the reference members (see below for what I try
to do).
#include <vector>
class TestClass {
private:
const int & m_q;
public:
TestClass(const int & q) { m_q = q; }
};
int main()
{
std::vector<TestClass> v;
int hello = 5;
v.push_back(TestClass(hello));
}
I would have expected that a copy constructor call would be executed in
the offended line instead of an assignment.
Can anyone explain how the desired operation could be implemented (or
why it doesn't make sense for me to want it to work?).
Best regards, Sidney