i cannot figure out how to solve this. I am coding a Container Class and run into a Problem with my constructor. I wanna take a variadic list of arguments of the specified type and add them to my array like f.ex. std::vector can do, but this does not work. Why and how to fix that?
it's not just "not working", it's saying exactly what's wrong:
no matching function for call to 'ContainerList<int>::push_back(int&, int&, int&)'
note: candidate: 'void ContainerList<VTYPE>::push_back(VTYPE) [with VTYPE = int]'
note: candidate expects 1 argument, 3 provided
There are many other things to fix in this code, but the minimal fix for this error message is to re-write line 39 so it calls the 1-argument push_back 3 times, rather than non-existent 3-argument push_back 1 time ContainerList(VTLST... arg) { (push_back(arg), ...);}
To have a proper RAII class, ensure in the destructor that you delete all the things you made with new . At the moment you run the risk of memory leakage when faced with an exception. https://en.cppreference.com/w/cpp/language/raii
Use std::size_t , not a naked size_t.
If you have begin() and end() defined, or the object is an array, and you wish to iterate the whole container, you can use a range based for loop.