Thursday, July 19, 2007

A class is not a namespace

Because the scope operator makes no difference between classes and namespaces people tend to think, that classes are like namespaces. But this is not true, as
  • classes can not nest further namespaces, only further classes
  • classes can not be imported by a using decleration
  • classes can not be reopenend
  • classes have access rights
One of the consequences is, that the "nest the enum into a namespace in order to import all constants"-trick and the "replace all enums by namespaces with constant integers"-workaround from my previous post do not work, if the enum is defined inside a class.

No comments:

Post a Comment