dimanche 28 juin 2020

Defining a parameter of a struct variable in a class constructor

I am using a struct variable inside a class and I would like to assign the value of a parameter of that variable in the class constructor.

But I can not find a way to compile. could you show me how to do it? This is an example of my code

struct mystruct
{
   int myvar;
}

class myclass
{
   mystruct s_;

public:
   myclass(int n) : s_.myvar{ n } {}
};

Aucun commentaire:

Enregistrer un commentaire