I am new to C++, and my question might be trivial, but I wasn't able to find a solution.
I have two classes, S
and L
. S
looks like this:
class S
{
private:
int m_x;
public:
S(int x) : m_x(x)
{
}
int m_y = 2*m_x; // some random action in S
};
Now I have a second class L
, where I want to initialize an S
-object:
class L
{
private:
S s(10); // 10 is just some random value
int m_y;
public:
L(int y): m_y(y)
{
}
// ignore the rest for now.
};
This produces an error error: expected identifier before numeric constant
at the line of initialization of s(10)
.
I don't understand why I can't do that. How could I fix this? What if I wanted to initialize the object S s(m_y)
instead?