C
Claudio Jolowicz
Is it possible to store unique objects in an STL container?
Suppose an object of class C is unique:
class C
{
public:
C() {}
~C() {}
private:
C(const C&);
operator=(const C&);
};
Another class manages and operates on collections of these objects:
class User
{
public:
void addC(const C& c)
{
m_lstCs.push_back(c);//error!
}
protected:
std::list<C> m_lstCs;
};
This leads to an error, because std::list<C>:ush_back() calls C's
copy constructor. Is a list of pointers the only solution, or is there
a better way?
--
Claudio Jolowicz
Department of Computing
180 Queen's Gate
South Kensington campus
Imperial College
LONDON SW7 2AZ
http://www.doc.ic.ac.uk/~cj603
Suppose an object of class C is unique:
class C
{
public:
C() {}
~C() {}
private:
C(const C&);
operator=(const C&);
};
Another class manages and operates on collections of these objects:
class User
{
public:
void addC(const C& c)
{
m_lstCs.push_back(c);//error!
}
protected:
std::list<C> m_lstCs;
};
This leads to an error, because std::list<C>:ush_back() calls C's
copy constructor. Is a list of pointers the only solution, or is there
a better way?
--
Claudio Jolowicz
Department of Computing
180 Queen's Gate
South Kensington campus
Imperial College
LONDON SW7 2AZ
http://www.doc.ic.ac.uk/~cj603