0

I have been exploring more C++ and encountered a phenomenon like Unnamed classes.

  class : public classB{
        public:
        protected:
        private:
  };

How are these classes useful? Is it like the concept of lambda functions?

I would like to know the purpose of such classes. The other threads don't really show any usefulness of the feature.

theta
  • 179
  • 11
  • Another good post about it is http://stackoverflow.com/questions/991062/passing-unnamed-classes-through-functions – AurA Jul 24 '13 at 18:08
  • That thread doesn't help me understand it. – theta Jul 24 '13 at 18:08
  • Unnamed structs existed in C. Consider `struct Foo { int d; };`, in C you could not say `Foo x;`, you had to `struct Foo x;`. Then you saw code like `struct Foo { int d; }; typedef struct Foo Foo;` which allows both uses. Or `typedef struct Foo { int d; } Foo;` which is the same. And if you only need the short form, `typedef struct { int d; } Foo;` is enough. And if you only want a variable to use its members directly and never need the type name, `struct { int d; } x = { 42 }; printf("%d\n", x.d);` is allowed. – gx_ Jul 24 '13 at 18:24

0 Answers0