2,926 questions
16
votes
3
answers
913
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
202
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
79
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
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....
0
votes
2
answers
58
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
73
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
45
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
43
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
69
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
49
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
93
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
180
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, ...
12
votes
1
answer
303
views
Does a constructor parameter of a nested class shadow members of the enclosing class?
class A
{
private:
int a;
public:
class B
{
public:
B(int a) : b(a) {}
int b;
};
};
int main(void)
{
return 0;
}
clang (-Weverything) warns:
t.cpp(10,15):...
0
votes
0
answers
62
views
Adding complex objects in .NET Core
These are my entities:
public class Order
{
[Key]
public long OrderId { get; set; }
public string CustomerId { get; set; }
[ForeignKey("CustomerID")]
[Required]
...
1
vote
0
answers
183
views
How can I overload a constructor in a private nested class without getting a "Resource Not Found" error when I call Inherited Create?
I have a Managed Record named TEmail with a nested private class called TEmailForm that inherits from TForm. The idea is my email Record can create a modal form as needed for the user to type an email....
0
votes
1
answer
76
views
Why do we use the new operator to access the nested static class in Java?
The below is the Employee class which has a public static nested class called EmployeeNameComparator .
import java.util.Comparator;
public class Employee {
public static class ...
-3
votes
1
answer
45
views
c# Nested data class is not recognized and gives error "Object reference not set to an instance of an object." [duplicate]
I have this simple application to populate fields from a data model, The data model is called Order which has a nested class called Address. When I attempt to assign a value to Order.Address.city, I ...
1
vote
2
answers
145
views
Changing colored cell in GridPane in JavaFX
I want to write code, that can do following:
Create 9*9 GridPane board that filled with 81 StackPanes.
When I click on cell (StackPane) I want to change color of background StackPane to blue if it ...
0
votes
0
answers
50
views
How to use templates with C++ inner class [duplicate]
Consider the following C++ code:
#include <iostream>
#include <memory>
template<typename T>
class MyClass
{
public:
struct InnerStruct
{
...
-1
votes
1
answer
126
views
Mockito instance of inner class
simpleJDBCCall.returningResultSet("test", new RowMapper<SomeObject> {
@Override
public SomeObject mapRow(Resultset r, int i) throws sqlexception {
//-----some code----
return ...
2
votes
0
answers
81
views
What is the use case of having static members inside a Method local inner class in Java?
I was completely blown away after I made a static member in Method local inner class, I am wondering what might be its use case as the scope of MLIC member is only inside the method in which they are ...
0
votes
0
answers
70
views
How to nest template classes in Kotlin
I'm trying to write some Kotlin code to encapsulate the idea of fields and elements in a field (with a view towards doing some work with finite fields).
I'd like the classes to be tightly coupled ...
0
votes
1
answer
84
views
Why would I not be able to access a method from an extended nested class?
I'm attempting to access a method inside a nested class that my class extends.
Specifically, it's the getSenderSubID() method in quickfix.fix42.Message.Header.
public class ExecutionReport extends ...
0
votes
0
answers
70
views
How to call the constructor of an inner class in a Scala 3 macro?
I'm trying to use a macro to save the code used to create a function for pretty-printing. Except the function is used in the constructor of an inner class. I had this working when the class was ...
0
votes
2
answers
102
views
Python Nesting Inner Classes - Object Programming [duplicate]
I would like to understand Python classes and objects.
I am trying and struggling to get the output results from inner-class, Features.
class Person:
def __init__(self):
pass
def ...
1
vote
1
answer
73
views
How to properly type nested classes with generics in C#
I'm trying to get the C# equivalent of this Kotlin code:
class Baz<E>(val value: E)
class Foo<T>(val toto: Baz<T>) {
class Bar<U>(toto: Baz<U>) : Foo<U>(toto) ...
-1
votes
2
answers
120
views
Mutually referencing nested classes in C++
I have a number of situations where I need to mutually reference nested classes e.g.
class C1;
class C2;
// class C2::S; // not allowed by the standard
template <class T> class R
{
T* t = ...
0
votes
0
answers
51
views
Linking error due to `<<` overload inside class nested within templated class [duplicate]
I am trying to overload the stream insertion operator << to allow instances of my gml::tensor<T>::shape class to be printed to stdout.
I have reduced my code as much as possible in order ...
0
votes
1
answer
63
views
Python: typing, how to use an inner class from another inner class?
Is it possible to specify a parameter of an inner class function as being types as another inner class?
class MyClass():
class InnerClass1():
pass
class InnerClass2():
...
1
vote
1
answer
91
views
Multiple instances of inner classes in Python
I'm trying to create a Child class within a Person class, but am having trouble accessing the child object after creation, when more than one instance is created dynamically.
For example, I ask the ...
0
votes
0
answers
61
views
Java: How to extend a inner class from different file [duplicate]
say I have these two classes in a single file where class A is a top level class:
class A{
class B{
}
}
how to make another top level class, say class C, extend class B without making B ...
1
vote
2
answers
701
views
"Constructor of inner class can be called only with receiver of containing class" when I create inner classs instance in constructor
I have a class
data classOuter (
val str: String = "fOo"
...
val innerClassInstance: InnerClass= InnerClass(),
) {
...
inner class InnerClass {
fun foo () {
...
1
vote
1
answer
119
views
Can we declare interface inside a method?
"You cannot declare an interface inside a block; interfaces are inherently static" This is sentence from https://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html#local-classes-...
0
votes
1
answer
156
views
How to override an abstract inner class of an abstract class in their subclasses (kotlin or java)
So basically I have a abstract class representing a BinaryTree below. I want to create a subclass called RBTree which will take advantage of all the abstraction in BinaryTree including the ability to ...
2
votes
1
answer
43
views
Between outer and inner classes, their static initializers run order is different when invoking main method inside or outside the outer class
I have the following code:
class Foo {
static { //static initializer block
System.out.print("Foo");
}
class Bar {
static { //static initializer block
...
2
votes
3
answers
2k
views
UML Class Diagram with Struct Defined Inside Class
How would a UML diagram look like for the case of the class containing structs which only exist during the life-time of the class?
Disclaimer:
I saw that there are similar questions, but mine differs ...
2
votes
1
answer
96
views
Inner classes can't reference eachother, is there a more Pythonic way?
I want to use inner classes (mainly dataclass and Enums) to keep things encapsulated. They hold data and defines that are only relevant to the main class, so I'd like to keep them inside it. I get the ...
2
votes
0
answers
313
views
Nested dataclass introducing memory leak, but gc.get_objects() has constant length
Salut community,
I had a problem with leaking memory in some code of mine and posted a question on this board (Issue with python memory management). Through some inspection I found what I had to ...
0
votes
2
answers
122
views
How do I instantiate structs inside a nested class?
So I googled everywhere and cannot get a straight answer to my problem. I haven't touch C++ in a while so I wanted to approach a minimalist coding structure, but I ran into a problem.
I have a parent ...
1
vote
0
answers
50
views
Extension Methods for Inner Class?
Is it possible to define an extension method for an inner class? The syntax reference seems to show it is possible to have a UsingParamClause before the DefParam, which is promising, and motivates the ...
-2
votes
2
answers
793
views
Inner classes can have the static members inside it in java 17? [duplicate]
I was reading the articles regarding the inner classes and out of curiosity I declared the static members within the inner class. Strangely no compile time error was shown and the code just executed ...
1
vote
1
answer
758
views
Access instance of outer class from mixin to inner class
I'm targeting a non-static nested class, e.g.
package whatever;
class Outer {
public int x;
class Inner {
public void foo();
}
}
And I would like to write a SpongePowered Mixin ...
0
votes
2
answers
123
views
Java: accessing a non-static field in an anonymous class in a static context
Consider the following class:
public class DataStructure {
// Create an array
private final static int SIZE = 15;
private int[] arrayOfInts = new int[SIZE];
public DataStructure()...
1
vote
2
answers
130
views
( modifier 'static' is only allowed in constant variable declarations ) compilation error
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java....
0
votes
2
answers
72
views
Nested class accessing outer class attributes without passing reference
I have a nested class and I would like it to have access to the attributes of the outer class. I've seen this done on other SO topics (here and some others). However, they always give a reference to ...
2
votes
1
answer
140
views
Is there a way to use Scanners in an inner class inside of Java without an exception
I have a Top-level public class with an inner class being created in that same class by creating an instance of the top-level class and then creating an instance of the inner class in that instance of ...
0
votes
0
answers
151
views
why the nested class will call the method of out class when the method not exist in nested class
class Outer {
static void out() {
System.out.println("hello world");
}
static class Inner {
}
static void main(String[] args) {
//Intellij Note: No ...