Click to See Complete Forum and Search --> : Local Class


ksrameshkanth
October 12th, 2005, 01:55 AM
why local class cannot have static member?

exterminator
October 12th, 2005, 02:17 AM
why local class cannot have static member?
....because: Local classes don't have any linkage (neither internal nor external). However they can access static variables defined in the enclosing scope. You may want to have a look at this - Local Classes (http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=191&rl=1). Hope this helps. Regards.

Naumaan
October 12th, 2005, 02:33 AM
the static keyword specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends) and initializes it to 0 unless another value is specified.
Actually local classes are "disposable classes", we use a local class to define a function object that is accessible only from within its scope. so its pointless to allow static variables in disposable class.