c++ 如何从函数返回vectors类的向量?[已关闭]

pod7payv  于 2022-12-24  发布在  其他
关注(0)|答案(1)|浏览(125)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
3天前关闭。
Improve this question
我试图在我创建的函数中返回一个向量的向量,但是我得到了“没有合适的用户定义转换”的错误。向量是类对象的向量。

/**function to get number of entries into an vector and pushback*/
std::vector<OrderBookEntry> AdvisorBot::EntryCount(std::string count,std::string tokens_string)
{
    //now use the tokenize func to get the string of each input
    std::vector<std::string> Tokens = CSVReader::tokenise(tokens_string, ',');

    std::string CountUserInput = count;
    int steps = std::stoi(CountUserInput);

    //pushback to entries vector of vectors
    std::vector< std::vector<OrderBookEntry> > Total_entries;

   
    for (int i = 0; i < steps; ++i) {
        if (i == 0) {
            Total_entries.push_back(AdvisorBot_orderBook.getOrders(OrderBookEntry::stringToOrderBookType(Tokens[1]), Tokens[0], currentTime));
        }
        else {
            currentTime = AdvisorBot_orderBook.getNextTime(currentTime);
            Total_entries.push_back(AdvisorBot_orderBook.getOrders(OrderBookEntry::stringToOrderBookType(Tokens[1]), Tokens[0], currentTime));
        }
    }
    //return std::vector<OrderBookEntry>();
    return Total_entries;

}

我只想返回我创建的向量Total Entries的向量。

oo7oh9g9

oo7oh9g91#

在c++中,返回数据类型是指定的。Total_entriesstd::vector<std::vector<OrderBookEntry>>类型,因此将返回类型更改为该类型。

std::vector<std::vector<OrderBookEntry>> AdvisorBot::EntryCount(std::string count,std::string tokens_string)
{
    //now use the tokenize func to get the string of each input
    std::vector<std::string> Tokens = CSVReader::tokenise(tokens_string, ',');

    std::string CountUserInput = count;
    int steps = std::stoi(CountUserInput);

    //pushback to entries vector of vectors
    std::vector< std::vector<OrderBookEntry> > Total_entries;

   
    for (int i = 0; i < steps; ++i) {
        if (i == 0) {
            Total_entries.push_back(AdvisorBot_orderBook.getOrders(OrderBookEntry::stringToOrderBookType(Tokens[1]), Tokens[0], currentTime));
        }
        else {
            currentTime = AdvisorBot_orderBook.getNextTime(currentTime);
            Total_entries.push_back(AdvisorBot_orderBook.getOrders(OrderBookEntry::stringToOrderBookType(Tokens[1]), Tokens[0], currentTime));
        }
    }
    //return std::vector<OrderBookEntry>();
    return Total_entries;

}

相关问题