nested-class

Are inner classes in C++ automatically friends?

冷暖自知 提交于 2019-11-26 06:36:33
问题 If I define an inner class in C++, is it automatically a friend of the class that contains it? For example, is this legal: class Outer { public: class Inner { public: void mutateOuter(Outer& o); }; private: int value; }; void Outer::Inner::mutateOuter(Outer& o) { o.value ++; // Legal? Or not? } I ask because on some compilers I\'ve tried (VS2003) this code won\'t work, but I\'ve heard at least anecdotally that it does work on some compilers. I can\'t find a relevant section in the C++ spec

Why Would I Ever Need to Use C# Nested Classes [duplicate]

那年仲夏 提交于 2019-11-26 02:42:11
This question already has an answer here: Why/when should you use nested classes in .net? Or shouldn't you? 13 answers I'm trying to understand about nested classes in C#. I understand that a nested class is a class that is defined within another class, what I don't get is why I would ever need to do this. A pattern that I particularly like is to combine nested classes with the factory pattern: public abstract class BankAccount { private BankAccount() {} // prevent third-party subclassing. private sealed class SavingsAccount : BankAccount { ... } private sealed class ChequingAccount :

Why Would I Ever Need to Use C# Nested Classes [duplicate]

廉价感情. 提交于 2019-11-26 01:12:47
问题 This question already has an answer here: Why/when should you use nested classes in .net? Or shouldn't you? 13 answers I\'m trying to understand about nested classes in C#. I understand that a nested class is a class that is defined within another class, what I don\'t get is why I would ever need to do this. 回答1: A pattern that I particularly like is to combine nested classes with the factory pattern: public abstract class BankAccount { private BankAccount() {} // prevent third-party