0

According to Herbert schildt C++ complete reference "A non-static member variable cannot have an initializer."
however when i run following code,it runs..

class ABC
{

public:
int a=3; 
ABC();


};

ABC::ABC()
{cout<<a;
}
int main()
{
ABC obj;
}

regards,

2
Contributors
1
Reply
20
Views
3 Years
Discussion Span
Last Post by deceptikon
1

It largely depends on your compiler and switches. C++11 (the latest standard) added this feature, and some compilers prior to that offered it as an extension.

Your book is old, by the way, and also written by an author who's routinely mocked for making grievous beginner mistakes. You might consider getting a different one.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.