All Questions
Tagged with nested-class or inner-classes
2,926 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
16
votes
3
answers
965
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
253
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
207
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 ...
0
votes
1
answer
80
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, ...
1
vote
1
answer
73
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....
0
votes
2
answers
59
views
How can I override super.nested test class?
Say, I have an abstract superclass and an abstract test class for testing subclasses.
abstract class Superclass {
}
@RequiredArgsConstructor
abstract class SuperclassTest<T extends Superclass> {...
0
votes
0
answers
74
views
Scala Compiler Error: Type Not Found in Derived Class When Extending Trait with Inner Class Type Projection
The following scala3 code compiles:
trait Product
trait Provider[+P <: Product] {
def provide: P
}
class Outer extends Provider[Outer#Inner] {
override def provide:...
2
votes
1
answer
46
views
Type mismatch when using generics with abstract nested classes
I find an "Argument type mismatch" error in multiply function and don't know how to fix it. The code is:
abstract class Semigroup<T1> {
abstract val one: SemigroupElement<T1>
...
1
vote
1
answer
44
views
How can I fix this error with nested interfaces
In the code you can see nested interfaces.
The error in Intellij IDEA is:
Kotlin: None of the following candidates is applicable: :25
The error is in the line: return Integer(this.value + other.value)...
1
vote
0
answers
70
views
How to implement a class of a specialized template class
suppose I have a template class
template<typename T>
struct Foo {
struct Bar;
};
specializing Foo<int>::Bar
template<>
struct Foo<int>::Bar {
struct Private; // I ...
0
votes
2
answers
50
views
How to access the top level/enclosing class instance having the instance of the inner class [duplicate]
NOTE: I'm not talking about the way of accessing the enclosing class FROM the inner class, that is not the problem at all. What I'm talking about is the following:
class TopLevel {
class ...
-1
votes
2
answers
100
views
Why does Java allow static methods within an Inner class [duplicate]
Java shouldn't allow static methods within an inner class and yet this code compiles and runs. How is this possible?
class Test{
static int j=20;
public void m1() {
class Inner{
...
1
vote
0
answers
57
views
How to conditionally seriaize nested class with System.Text.Json?
I am looking to serialize a nested class on condition that value of an attribute is different than some custom value.
I was looking at: https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-...
0
votes
2
answers
182
views
Why does the constructor of a non-private inner member class need a variable representing the immediately enclosing instance of this class?
I am very curious about this question. The Java Language Specification has told me part of the reason:
In a class instance creation expression for a non-private inner member class, §15.9.2 specifies ...
0
votes
1
answer
133
views
How would one access an Inner class from outside of all classes?
I have a class (MainApplication) that envelopes all my other classes, and an if statement that is outside of the outer class. I'm struggling to figure out how to access 'Start' from that if statement, ...