2020-10-29

Invalid initializer for array member

I'm trying to specify an attribute of a class as being a array of 5 position of the type Stock like follows:

#include "stdio.h"
#include "string"
#include "array"
#include "./stock.h"

#ifndef WALLET_H

class Wallet {
  public:
    Wallet(std::string name, Stock stocks[5]) : name_(name), stocks_(stocks) {}

    //! Calculate de wallet return
    float wallet_return(Stock *stock);

    //! Return the name of the wallet
    std::string get_name();

    //! Return all the stocks in the wallet
    Stock* get_stocks();

  private:
    std::string name_;
    Stock stocks_[5];
};

#endif

std::string Wallet::get_name() {
  return name_;
}

Stock* Wallet::get_stocks() {
  return stocks_;
}

But I keep getting the error invalid initializer for array member 'Stock Wallet::stocks_ [5]', referring to the constructor method.

What I'm I doing wrong?



from Recent Questions - Stack Overflow https://ift.tt/3oF4Mnk
https://ift.tt/eA8V8J

No comments:

Post a Comment