jeudi 23 mai 2019

Create a constructor, that is capabe take any number of arguments

So the class B constructor should take any number of A* as arguments, and simply push_back these pointers to _vec vector.

I tried to use variadic templates, std::initalizer_list. Nothing seems to fit. Maybe I over complicate the problem here. Could not find a solution anywhere in the last 2 days.

//very shematic code, just to get the idea
Class A
{
    //members
};
Class B
{
private:
    std::vector<A*> _vec; 
public:
    B(A* much_arguments) 
    {
    _vec.push_back(much_arguments); //schematically
    //do other stuff;
    }
};

ps. Sorry but I cant format the code, old browser, no toolbar.

Aucun commentaire:

Enregistrer un commentaire