Quantcast
Channel: Why would one use nested classes in C++? - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by Yeo for Why would one use nested classes in C++?

One can implement a Builder pattern with nested class. Especially in C++, personally I find it semantically cleaner. For example: class Product{ public: class Builder; } class Product::Builder { //...

View Article



Answer by Kos for Why would one use nested classes in C++?

Nested classes are just like regular classes, but: they have additional access restriction (as all definitions inside a class definition do), they don't pollute the given namespace, e.g. global...

View Article

Answer by Martin York for Why would one use nested classes in C++?

Nested classes are cool for hiding implementation details. List: class List { public: List(): head(nullptr), tail(nullptr) {} private: class Node { public: int data; Node* next; Node* prev; }; private:...

View Article

Answer by John Dibling for Why would one use nested classes in C++?

I don't use nested classes much, but I do use them now and then. Especially when I define some kind of data type, and I then want to define a STL functor designed for that data type. For example,...

View Article

Why would one use nested classes in C++?

Can someone please point me towards some nice resources for understanding and using nested classes? I have some material like Programming Principles and things like this IBM Knowledge Center - Nested...

View Article


Answer by maxim for Why would one use nested classes in C++?

You also can think about first class ass type of main function, where You initiate all needed classes to work togheter. Like for example class Game, initiate all other classes like windows, heroes,...

View Article

Answer by Mikhail Veselov for Why would one use nested classes in C++?

I think the main purpose of making a class to be nested instead of just a friend class is the ability to inherit nested class within derived one. Friendship is not inherited in C++.

View Article
Browsing latest articles
Browse All 7 View Live




Latest Images