On Jul 14, 3:16*pm, Ian Collins <ian-n...@hotmail.comwrote:
Quote:
Originally Posted by
Anarki wrote:
Quote:
Originally Posted by
#include <iostream>
using namespace std;
|
>
Quote:
Originally Posted by
class ConstantMember1
{
* * * * const int m_const;
* * * * public:
* * * * ConstantMember1(int cons = 20){m_const = cons;}
* * * * int getConst() const{ return m_const;}
|
>
>
Quote:
Originally Posted by
int main()
{
* * * * ConstantMember1 Y;
* * * * cout << X.getConst();
* * * * return 0;
|
>
>
Quote:
Originally Posted by
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.
Quote:
Originally Posted by
>
The only way to initialise a const member is with an initialiser list.
>
Quote:
Originally Posted by
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.
Quote:
Originally Posted by
>
--
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......