How can I initilise a structure in the constructor list?
Say:
struct St{int x, y};
class Foo
{
public:
Foo(int a = 0, int b = 0) : /*here initilise st_foo out of a and b*/
{}
private:
const St st_foo;
};
How can I initilise a structure in the constructor list?
Say:
struct St{int x, y};
class Foo
{
public:
Foo(int a = 0, int b = 0) : /*here initilise st_foo out of a and b*/
{}
private:
const St st_foo;
};
You need to provide a constructor for struct St
that takes 2 int
parameters and assigns them to x
and y
. Then invoke it in your Foo
initialization list.
Remember: structs are the same thing as classes except default visibility rules (for structs, default is public
.