Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VC++6 error C2059: syntax error : 'constant'

Made this simple class with MSVC++ 6.0

class Strg
{
public:
    Strg(int max);
private:
    int _max;
};


Strg::Strg(int max)
{
  _max=max;
}

Sounds good if I use it in :

main()
{
  Strg mvar(10);
}

But Now If I use it in an another class :

class ok
{
public:
    Strg v(45);
};

I get message error : error C2059: syntax error : 'constant'

Could you tell me more please ?


1 Answers

Should be:

class ok
{
public:
    Strg v;
    ok() : v(45) {}
};

Non-static member variables that don't have default constructors (v in this case) should be initialized using initialization lists. In functions (like main) on the other hand you can use the regular constructor syntax.

like image 177
Firas Assaad Avatar answered Dec 05 '25 22:12

Firas Assaad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!