why can't we declare data member of class auto register or extern
-
thank u in advance
-
thank u in advance
Because none of those make sense used on a class member. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Because none of those make sense used on a class member. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
but when we write like class a { int i; }; then obviously by default data type of i is auto int my question is why compiler don't accept this,and why none of those make sense as you wrote. if u have any link related to this question please send me thank u in advance
-
but when we write like class a { int i; }; then obviously by default data type of i is auto int my question is why compiler don't accept this,and why none of those make sense as you wrote. if u have any link related to this question please send me thank u in advance
rajneshmalik wrote:
then obviously by default data type of i is auto int
No, it isn't. i is a class member. auto variables have a local lifetime - the lifetime of i is determined by the lifetime of the object it is in. register - same thing. You've only declared i. Until there's an instance of an "a" object, i doesn't exist. How, then, can you give i a storage specifier? extern? Makes NO sense. How can a member of an object be somewhere else - some external location?
Mark Salsbery Microsoft MVP - Visual C++ :java: