nested-class

Nested C# Classes - Calling Outer Method From Inner

I have a ViewController class called GamePlay. In GamePlay there is a nested class called MyPinAnnotationView. When MyPinAnnotation's method TouchesBegan() gets called, I want to call a method CheckAnswer() from the parent GamePlay. I do not want to create a new GamePlay instance because I have variables and instances already set. C...

Nested class forward declaration for template inheritance

What's the proper way to inherit from a template class with the template argument being a nested class within the inheriting class? class SomeClass : public TemplateClass<NestedClass> { class NestedClass {}; }; ...

Templates, nested classes, and "expected constructor, destructor, or conversion before '&' token"

While working with some templates and writing myself a basic container class with iterators, I found myself needing to move the body of member functions from a template class into a separate file to conform to style guidelines. However, I've run into an interesting compile error: runtimearray.cpp:17: error: expected constructor, de...

Accessing Outer class attribute from an instance of an Inner class.

Given the following code: public class Outer { public final int n; public class Inner implements Comparable<Inner> { public int compareTo(Inner that) throws ClassCastException { if (Outer.this.n != Outer.that.n) // pseudo-code line { throw new ClassCastException("Only Inners with t...

Inner class in interface vs in class

What is the difference between these two innerclass declarations? Also comment on advantages/disadvantages? case A: class within a class. public class Levels { static public class Items { public String value; public String path; public String getValue() { return value;} } } and case B: class within interface...

Nested Singleton Class

Is it possible to nest a singleton class inside a non-singleton class in C#, and if so, are there any restrictions to the life-cycle of the singleton in this case? public class NonSingletonClass { public NonSingletonClass() { // Initialize some stuff. } // Put some methods here. public class SingletonClass { // Sin...

Interfaces, Static Inner Classes and Best Practices

So, this is a question of coding style more or less. I'm using Bean Validation here but the idea is the same for any interface that has simple implementations that aren't likely to get changed all that often. @Target( { METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = PhoneNumber.PhoneNumberValidator.clas...

Java: return static nested class

Hi, I have a static nested class, which I would like to return via a static accessor (getter). public class SomeClass { public static class Columns<CC> { ... public static int length = 5; } public static Columns<?> getColumnEnumerator() { int x = Columns.length; //no problems retur...

Does SwingWorker has to be a nested class?

Hi there. I'm wondering if SwingWorker has to be a nested class within my main GUI. I'd rather make it an external class to keep the GUI clear from any of my programs logic. I tried to make the SwingWorker class external, which works fine for the process, unfortunately I can't access any of my GUI fields from the SwingWorker class. When...

Nested types that are public

Hi, I'm curious as to what is good practice when it comes to certain scenarios involving nested types in .NET. Lets say you have a Wheel class, and the Wheel class holds Bearing objects. A Bearing object only makes sense within a Wheel and you do not want to allow it to be created independently, so it would make sense to have the Bear...

C++ visibility of privately inherited typedefs to nested classes

First time on StackOverflow, so please be tolerant. In the following example (apologies for the length) I have tried to isolate some unexpected behaviour I've encountered when using nested classes within a class that privately inherits from another. I've often seen statements to the effect that there is nothing special about a nested cl...

Nested class or not nested class?

I have class A and list of A objects. A has a function f that should be executed every X seconds (for the first instance every 1 second, for the seconds instance every 5 seconds, etc.). I have a scheduler class that is responsible to execute the functions at the correct time. What i thought to do is to create a new class, ATime, that wil...

Class.Class vs Namespace.Class for top level general use class libraries?

Which one is more acceptable (best-practice)?: namespace NP public static class IO public static class Xml ... // extension methods using NP; IO.GetAvailableResources (); vs public static class NP public static class IO public static class Xml ... // extension methods NP.IO.GetAvailableResources (); Also ...

gcc returns error with nested class

Howdy, I am attempting to use the fully qualified name of my nested class as below, but the compiler is balking! template <class T> class Apple { //constructors, members, whatevers, etc... public: class Banana { public: Banana() { //etc... } //other constructors, members, etc... }; };...

Return pointer to nested inner class from generic outer class

I'm new to C++, so bear with me. I have a generic class called A. A has a nested class called B. A contains a method called getB(), which is supposed to return a new instance of B. However, I can't get my code to compile. Here's what it looks like:#include A.h template <class E> class A { public: class B { public: ...

Accress Parent Page's Viewstate in ASP.NET

OK, I guess I'm missing something obvious here, but I still can't make it work... I have a page in ASP.NET. I have a nested class inside the page. I have a property in this nested class. How can I access the page's viewstate from the property's Set statement? Thanks! ...

C++ nested class/forward declaration issue

Is it possible to forward-declare a nested class, then use it as the type for a concrete (not pointer to/reference to) data member of the outer class? I.E. class Outer; class Outer::MaybeThisWay // Error: Outer is undefined { }; class Outer { MaybeThisWay x; class MaybeThatOtherWay; MaybeThatOtherWay y; // Error: MaybeThatOt...

PHP Nested classes work... sort of?

So, if you try to do a nested class like this: //nestedtest.php class nestedTest{ function test(){ class E extends Exception{} throw new E; } } You will get an error Fatal error: Class declarations may not be nested in [...] but if you have a class in a separate file like so: //nestedtest2.php class neste...

In java what are nested classes and what do they do?

In java what are nested classes and what do they do? ...

Can a Static Nested Class be Instantiated Multiple Times?

Given what I know of every other type of static feature of programming––I would think the answer is 'no'. However, seeing statements like OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass(); makes me wonder. ...