nested-class

Why can't a class extend its own nested class in C#?

删除回忆录丶 提交于 2019-11-27 01:15:34
问题 For example: public class A : A.B { public class B { } } Which generates this error from the compiler: Circular base class dependency involving 'A' and 'A.B' I always figured a nested class behaved just like a regular class except with special rules concerning accessing the outer class's private members, but I guess there's some implicit inheritance occurring between the two classes? 回答1: There's no implicit inheritance involved as far as I can tell. I would have expected this to be okay -

How to restrict access to nested class member to enclosing class?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 19:58:55
Is it possible to specify that members of a nested class can be accessed by the enclosing class, but not other classes ? Here's an illustration of the problem (of course my actual code is a bit more complex...) : public class Journal { public class JournalEntry { public JournalEntry(object value) { this.Timestamp = DateTime.Now; this.Value = value; } public DateTime Timestamp { get; private set; } public object Value { get; private set; } } // ... } I would like to prevent client code from creating instances of JournalEntry , but Journal must be able to create them. If I make the constructor

Are inner classes in C++ automatically friends?

孤人 提交于 2019-11-26 18:48:45
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 about this, and if anyone can cite something specific that would say that it is or is not legal that would be

How to use nested class in WPF XAML?

為{幸葍}努か 提交于 2019-11-26 18:25:40
问题 I am refactoring the code from sample: 24.129.21. Master Detail Binding from C# / CSharp Tutorial » Windows Presentation Foundation » Binding) And after excluding Skills class, with corresponding changes in in MainWindow.xaml <local:Team> <local:Employee Name="Larry" Age="21"> <local:Employee.Skills> <!-- local:Skills --> <local:Skills> in MainWindow1.xaml.cs : using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; namespace WpfApplication { public class

Eclipse warning about synthetic accessor for private static nested classes in Java?

流过昼夜 提交于 2019-11-26 16:12:00
问题 My coworker suggested making several of the Eclipse code-formatting and warning settings to be more rigorous. The majority of these changes make sense, but I get this one weird warning in Java. Here's some test code to reproduce the "problem": package com.example.bugs; public class WeirdInnerClassJavaWarning { private static class InnerClass { public void doSomething() {} } final private InnerClass anInstance; { this.anInstance = new InnerClass(); // !!! this.anInstance.doSomething(); } } //

Dependent scope and nested templates

℡╲_俬逩灬. 提交于 2019-11-26 15:58:30
问题 When I compile this: #ifndef BTREE_H #define BTREE_H #include <QList> template <class T, int degree> class btree { public: class node { public : node(); private: node* parent; QList<T> values; QList<node*> children; }; public: btree(); void insert(const T& value); node* findLeaf(const T& value); void performInsertion(const T& value, node& place); // node* root; }; #endif // BTREE_H Implementation of findLeaf is this: template <class T, int degree> btree<T,degree>::node* btree<T,degree>:

Using nested enum types in Java

假装没事ソ 提交于 2019-11-26 15:48:18
问题 I have a data structure in mind that involves nested enums, such that I could do something like the following: Drink.COFFEE.getGroupName(); Drink.COFFEE.COLUMBIAN.getLabel(); And if there were method declarations: someMethod(Drink type) someOtherMethod(DrinkTypeInterface type) Then I could say (appropriately): someMethod(Drink.COFFEE) someOtherMethod(Drink.COFFEE.COLUMBIAN) This is what I came up with: public enum Drink { COFFEE("Coffee"); private String groupName; private Drink(String

Creating an instance of a nested class in XAML

与世无争的帅哥 提交于 2019-11-26 11:06:27
问题 in a XAML file (a WPF UserControl), is there a way to reference an inner class \"B\" defined in another class \"A\" ? public class A { public class B { } } Something like : <local:A.B ... /> This syntax does not work because \"B\" is interpreted as a property named \"B\" in class \"A\". I\'ve tried more exotic syntaxes like \"::\" or \"+\" but none seems to work. I\'m currently using Silverlight 4 with VS2010 . Thanks in advance for your help. 回答1: I was searching and searching, because if

What are reasons why one would want to use nested classes? [duplicate]

爱⌒轻易说出口 提交于 2019-11-26 10:58:24
问题 This question already has answers here : Why/when should you use nested classes in .net? Or shouldn't you? (13 answers) Closed 6 years ago . In this stackoverflow answer a commenter mentioned that \" private nested classes\" can be quite useful so I was reading about them in articles such as this one which tend to explain how nested classes function technically , but not why you would use them. I suppose I would use private nested classes for little helper classes that belong to a larger

How to restrict access to nested class member to enclosing class?

百般思念 提交于 2019-11-26 07:28:15
问题 Is it possible to specify that members of a nested class can be accessed by the enclosing class, but not other classes ? Here\'s an illustration of the problem (of course my actual code is a bit more complex...) : public class Journal { public class JournalEntry { public JournalEntry(object value) { this.Timestamp = DateTime.Now; this.Value = value; } public DateTime Timestamp { get; private set; } public object Value { get; private set; } } // ... } I would like to prevent client code from