Martin
Martin

Reputation: 39

Constructor of a class with an attribute that is another class object

Constructor declaration:

Funcion(std::string cveFunc=" ", int numP = 0, Hora hour(0,0), int room=0);

Constructor:

Funcion::Funcion(std::string cveFunc, int numP, Hora hour(), int room) : 
    cveFuncion{cveFunc}, numPeli{numP}, hora hour = {}, sala{room}{}

The problem is with the attribute hour i don't know how to declare it correctly.

This is the class hora constructor:

inside class:

Hora(int hhh=0, int mmm=0);

outside class:

Hora::Hora(int hhh, int mmm) : hh{hhh}, mm{mmm} {}

Upvotes: 0

Views: 61

Answers (1)

R Sahu
R Sahu

Reputation: 206667

Use of

Funcion::Funcion(std::string cveFunc, int numP, Hora hour(), int room)

is wrong because in that context hour is declared as a function that takes no arguments and returns an Hour. You need to remove the (). Use:

Funcion::Funcion(std::string cveFunc, int numP, Hora hour, int room)

Assuming hora is the member variable of the class, the member initialization also needs to be updated to:

cveFuncion{cveFunc}, numPeli{numP}, hora {hour}, sala{room}

Put together, you have:

Funcion::Funcion(std::string cveFunc, int numP, Hora hour, int room) :
        cveFuncion{cveFunc}, numPeli{numP}, hora {hour}, sala{room}{}

Upvotes: 1

Related Questions