mardi 13 décembre 2022

trying to call non static function outside class in c++ [closed]

I'm working on a cryptocurrency app (for uni) and I have a class called orderBook which reads data off CSV file and does some processing. One of the class' functions is getKnownProducts, which prints all currencies as strings.

OrderBookEntry is the main class with the constructor that contains all the datatypes of the data read from the CSV.

I want to call the function getKnownProducts in a function that lists all products.

    class OrderBook
{
    public:
    /** Construct, reading a csv file*/
        OrderBook(std::string filename);
     /** Return vector of all known products in the dataset*/
        std::vector<std::string> getKnownProducts();
     //some more code...
};

I made an instance in the main file

OrderBook OrderBook{"20200601.csv"};

And this is the implementation in the cpp file

std::vector<std::string> OrderBook::getKnownProducts()
{
    std::vector<std::string> products;

    std::map< std::string, bool> prodMap;

    for(OrderBookEntry& e : orders) 
    {
        prodMap[e.product] = true;
    }
    // Flatten map to a vector of strings
    for(const auto& productStringBoolPair : prodMap)
    {
        products.push_back(productStringBoolPair.first);
    }
    return products;
}

Finally, I tried to call getKnownProducts from the following function when I got the typename error

void printProducts()
{
    for(std::string const& p : OrderBook.getKnownProducts())
    {
        std::cout << "products: " << p << std::endl;
    }
}

Aucun commentaire:

Enregistrer un commentaire