#Changing the ''='' operator in a class?
8 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
You need to overload the copy constructor for std::initializer_list
class Set
{
public:
Set(std::initializer_list<int> il)
{
elements.resize(il.size());
for(std::size_t i = 0; i < il.size(); i++)
{
int val = *(il.begin() + i);
elements[i] = val;
}
}
private:
std::vector<int> elements;
};
int main ()
{
Set N = {1, 2, 3, 4, 5};
}