All Questions
Tagged with nested-class or inner-classes
2,868 questions
16 votes
3 answers
899 views
Necessity of `typename` for naming of local nested classes in function templates
I have a function template f, defining in its body a local class A with another nested class B. Both classes are not templates. Must I name the inner class as typename A::B or shorter variant A::B is ...
Advice
2 votes
4 replies
249 views
Can function-local class be defined in the global scope?
Any C++ class can be first forward declared, and defined only later in the program. Are function-local classes an exception from this rule? Please consider a simplified program: auto f() { struct ...
7 votes
1 answer
201 views
Visibility of C++ nested class complete definition in the presence of forward declarations
In C++, forward declarations introduce an incomplete type. Incomplete types can be used to declare pointers, but they cannot be used to initialize values or access members because the complete ...
2108 votes
28 answers
976k views
Java inner class and static nested class
What is the main difference between an inner class and a static nested class in Java? Does design / implementation play a role in choosing one of these?
419 votes
12 answers
398k views
Is not an enclosing class Java
I'm trying to make a Tetris game and I'm getting the compiler error when I try to create an object Shape is not an enclosing class public class Test { public static void main(String[] args) { ...
398 votes
15 answers
215k views
Difference between final and effectively final
I'm playing with lambdas in Java 8 and I came across warning local variables referenced from a lambda expression must be final or effectively final. I know that when I use variables inside anonymous ...
365 votes
11 answers
367k views
What causes error "No enclosing instance of type Foo is accessible" and how do I fix it?
I have the following code: class Hello { class Thing { public int size; Thing() { size = 0; } } public static void main(String[] args) { ...
0 votes
1 answer
77 views
Can nested classes or even anonymous classes extend a class or implement a interface? [closed]
Can nested classes or anonymous classes extend a class or implement an interface in Java? If so, are there any limitations or things I should be aware of? I'm not very familiar with nested classes, ...
250 votes
6 answers
242k views
Why would one use nested classes in C++? [closed]
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 ...
389 votes
8 answers
299k views
Java: Static vs inner class [duplicate]
What is the difference between static and non-static nested class?
191 votes
16 answers
181k views
How to access outer class from an inner class?
I have a situation like so... class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # &...
350 votes
3 answers
66k views
When exactly is it leak safe to use (anonymous) inner classes?
I have been reading some articles on memory leaks in Android and watched this interesting video from Google I/O on the subject. Still, I don't fully understand the concept, and especially when it is ...
1 vote
1 answer
72 views
Python static class variable in nested class
I have a nested class that uses static vars to have class wide parameters and accumulators. If I do it as a standalone class it works. If I do a nested class and inherit the standalone class, it works....
291 votes
7 answers
184k views
Getting hold of the outer class object from the inner class object
I have the following code. I want to get hold of the outer class object using which I created the inner class object inner. How can I do it? public class OuterClass { public class InnerClass { ...
149 votes
11 answers
167k views
Nested or Inner Class in PHP
I'd like to create a User Class for my new website. However, this time, I was thinking of creating it a little bit differently... Java, C++, and even Ruby (and probably other programming languages) ...