I'm doing an practice exercise from a book and I am having problems with initializing an array structure in a class.
I get multiple errors. one says a brace-enclosed initializer is not allowed here before '{' token.
another says ISO c++ forbids initialization of member 'drink'
third -making 'drink' satic
fourth error -invalid in class initialization of static data member of non integral type drinkInfo[3]
Can you help me find the error in the code?
Code:
#include <iostream>
#include <string>
using namespace std;
struct drinkInfo{
string name;
double price;
int quantity;
drinkInfo(string n, double p, int q){
name = n;
price = p;
quantity = q;
}
};
class machine {
private:
drinkInfo drink[3] = { drinkInfo("cola", 0.75, 20),
drinkInfo("sprite", 0.75, 20),
drinkInfo("root beer", 0.75, 20) };
};