Input values ​​to custom class with "<<"

I am new to C ++ and I am trying to figure out how to do the following:

I have a class that contains a QList. I am trying to populate a QList as shown below. I am wondering how can I achieve this? Is this done in the NumberList constructor? I used to populate myList using a method that takes a list of objects and retrieves them to populate a QList, but that won't work for my example below.

NumberList myList;
myList << 1 << 2 << 3;



source share

1 answer


NumberList & operator<<(NumberList & lhs, number_t rhs)
    return lhs;


Or, as a member function, it would look like this:

NumberList & NumberList::operator<<(number_t rhs)
    return *this;




All Articles