Hi NG,
I want to use a const member variable in a class like
class abc{
private :
const int x;
};
How can i Initialise this into some value.
I am using MS vc++ 6.0.
Regards\Raghuram.k
Printable View
Hi NG,
I want to use a const member variable in a class like
class abc{
private :
const int x;
};
How can i Initialise this into some value.
I am using MS vc++ 6.0.
Regards\Raghuram.k
You have to set it in a constructor initialiser list:
Code:class abc
{
public:
abc() : x(0) {}
abc(const abc& other) : x(other.x) {}
private:
const int x;
};