On Jul 14, 3:16*pm, Ian Collins <ian-n...@hotmail.comwrote:
Anarki wrote:
#include <iostream>
using namespace std;
class ConstantMember1
{
* * * * const int m_const;
* * * * public:
* * * * ConstantMember1(int cons = 20){m_const = cons;}
* * * * int getConst() const{ return m_const;}
};
int main()
{
* * * * ConstantMember1 Y;
* * * * cout << X.getConst();
* * * * return 0;
}
Why doesn't this program compile?
Too many bugs? *Your compiler errors should have been clear enough.
look friend i know the error is due to the constant variable in class.
But why should the compiler raise error? Am looking for more detailed
explanation.
>
The only way to initialise a const member is with an initialiser list.
What is the difference between the
constructor i gave in first post and this ( ConstantMember() and
ConstantMember1() )
You used an initialiser list.
i understand i used initialiser list but whats happening inside the
initialiser list? What does the compiler do when it see the
initialiser list. I think u didn't get what i meant. i explain a bit
more what's the difference between a normal constructor and
constructor that uses initialiser list.
>
--
Ian Collins.
The answer you gave me was just the technical term/terminology of the
example i posted. But what exactly is happening inside this
initialiser list?? Some one please help......