Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do you return a vector of tuple from a function?

I cant seem to figure this out for some reason, I have a function in my main that needs a class object and I cant figure out how to return it:

vector<tuple<Item, int>> Character::GetInventory() const




2 Answers

  • 1 month ago

    You have to create it first.  That will involve member variables and/or member function calls that you haven't listed.  A trivial sample might be something like:

    vector<tuple<Item, int>> Character::GetInventory() const


        vector<tuple<Item, int>> result;

        result.push_back(std::make_tuple(Item("vorpal sword"), 1));

        result.push_back(std::make_tuple(Item("no tea"), 999));

        return result;


  • Anonymous
    1 month ago

    Once upon a time, there was this guy who made art, and he took this pile of elephant poo and he put it on a canvas and he called it art.

Still have questions? Get your answers by asking now.