[Solved] C++ struct in a vector in an object(class)


The problem is that you define a type (account) in the class. account is a type so you should not declare it in the class :

struct account { std::string name;
                 float money;
                 short pin;
               };

and then, the class becomes :

class CBank
{
    public:
        CBank();
        account acc;
        std::vector<account> add;
};

and the main :

int main()
{
    CBank bank;

    bank.acc.name = "Alpha Omega";
    bank.acc.money = 15635.23;
    bank.acc.pin = 3241;

    bank.add.push_back(bank.acc);
    return 0;
}

3

solved C++ struct in a vector in an object(class)