A
Anarki
#include <iostream>
using namespace std;
class ConstantMember
{
const int m_const;
public:
ConstantMember(int cons = 10):m_const(cons){}
int getConst() const{ return m_const;}
};
int main()
{
ConstantMember X;//(20);
cout << X.getConst();
return 0;
}
the above is a program that was compiled & linked using g++. Is there
any other way to initialise a constant member variable using
constructor while creating objects?
using namespace std;
class ConstantMember
{
const int m_const;
public:
ConstantMember(int cons = 10):m_const(cons){}
int getConst() const{ return m_const;}
};
int main()
{
ConstantMember X;//(20);
cout << X.getConst();
return 0;
}
the above is a program that was compiled & linked using g++. Is there
any other way to initialise a constant member variable using
constructor while creating objects?