c++ - Input values into custom class with "<<" -
i new c++, , trying figure out how following:
i have class holds qlist. trying populate qlist demonstrated below. wondering how achieve this? done in numberlist constructor? populate mylist using method takes list of objects, , extracts them fill qlist, not work example below.
numberlist mylist; mylist << 1 << 2 << 3;
easy.
numberlist & operator<<(numberlist & lhs, number_t rhs) { lhs.append(rhs); return lhs; }
or, member function, this:
numberlist & numberlist::operator<<(number_t rhs) { append(rhs); return *this; }
Comments
Post a Comment