Hello,
why is the below declaration not working and what to do to make it a valid one?
Code:class shape { const int p; public: shape() { p=10; } void display() { cout<<p; } };
Hello,
why is the below declaration not working and what to do to make it a valid one?
Code:class shape { const int p; public: shape() { p=10; } void display() { cout<<p; } };
RED part was wrong!Code:class shape { const int p; public: shape() : p(10) { // p=10; } void display() { cout<<p; } };
GREEN part is added by me, and is the right way to do this!
Just a side note, if you decalre an array size in a class, make sure you make it static.
Code:class Foo { public: static const int ARRAY_SIZE = 10; };
Double Helix STL
Probabily you can do something like this:
Code:Class A { const int _p; public: A() : _p(10) { } //or A(int size) : _p(size) {} };