Local classes are classes that are defined in a block, which is a group of zero or more statements between balanced braces. You typically find local classes defined in the body of a method.
Questions tagged [local-class]
64 questions
2
votes
0 answers
Variable lookup in derived local class of template function
I'm experimenting with local classes in C++ and stuck with following code:
void f1(int a)
{
struct Inner1
{
int a;
};
struct Inner2 : Inner1
{
void foo()
{
a = 10; // Okay
}
…

hate-engine
- 2,300
- 18
- 26
2
votes
1 answer
unable to watch java local class instance in eclipse
Here is a small sample:
public class LocalClassSample {
public static void main(String[] args) {
class Utils {
public void printHello(String name) {
System.out.println("Hello " + name);
}
…

deostroll
- 11,661
- 21
- 90
- 161
2
votes
2 answers
Local class instance creation expression in a static-context
The JLS 15.9.2 tells us how to determine an enclosing instance:
Let C be the class being instantiated, and let i be the instance being created.
If C is an inner class, then i may have an immediately enclosing
instance (§8.1.3), determined as…

St.Antario
- 26,175
- 41
- 130
- 318
2
votes
2 answers
passing local class function pointer to std::list::sort
I am trying to sort a member variable type std::list using a local function. Since C++ doesn't allow local functions and hence Herb Sutter's suggests local classes, I ended up with the following code. But am not sure how I can pass a function…

Chenna V
- 10,185
- 11
- 77
- 104
2
votes
5 answers
Why can't create instance of local class in Java?
If I have this code.
public class Test{
{
class People {
}
}
public static void main(String[] args) {
People person = new People();//Compile ERROR
}
}
I can't create…

Xelian
- 16,680
- 25
- 99
- 152
2
votes
2 answers
Local classes inside inline non-member function produces LNK2005 with MSVC2005
Apparently, MSVC2005 fails to inline local classes' member functions which leads to LNK2005.
I'm facing this LNK2005 error when compiling the following:
common.h content:
inline void wait_what()
{
struct wtf
{
void ffffuuu() {}
}…

Gregory Pakosz
- 69,011
- 20
- 139
- 164
1
vote
1 answer
Why does Java complain that it can't find my local class?
I am trying to setup Dozer to perform a complex mapping between my two entities. Essentially, I want it to convert my percentCompleted double to a boolean, based on if the value is 1 (100%) or not.
To do this I created the following…

KallDrexx
- 27,229
- 33
- 143
- 254
1
vote
2 answers
Are all local classes and all anonymous classes also inner classes?
This question is mostly about proper Java terminology.
I am making the distinction between an inner class, which is tied to instance of its enclosing scope, and an non-inner, nested static class which is independent of an enclosing scope…

Gonen I
- 5,576
- 1
- 29
- 60
1
vote
1 answer
Use Clang LibTooling to scan C++ source that has call to local class in a templated parent class
Source code to scan:
template
class HB {
T m;
public:
void HBfunc1();
};
template
void HB::HBfunc1() {
class HC {
public:
void HCfunc2() { };
};
HC().HCfunc2();
}
void…

jw_
- 1,663
- 18
- 32
1
vote
4 answers
How to make function friend of local class?
Please read the code to know the problem :
#include
void fun(int value)
{
//starts local class definition
class test
{
int x;
public:
test(int a) : x(a) {}
void display() const
{
…
user11712295
1
vote
2 answers
How to reference local class
I have a local class...
public class Outer {
public void wrapper() {
class Local {
}
}
}
and I have a test that needs to reference the local class...
Outer.wrapper.Local.class ## this doesn't seem to work
How can I…

Brent Bradburn
- 51,587
- 17
- 154
- 173
1
vote
1 answer
Call Local class within PAI Module
I have a program with 4 includes in it. One top-include (global data), one for pai-modules, one for pbo-modules and one for a local helper class.
I put the definition and implementation of my local class in the include "local helper class". Now I…

Timur
- 169
- 4
- 13
1
vote
4 answers
Why does an inner class instance remian in the memory even if the outer class object is destroyed?
Please consider following two classes:
a.) Student
package datatypes;
public class Student {
private String name ;
public Student(String name) {
this.name = name;
}
class Address{
String city;
String…

Yati Sawhney
- 1,372
- 1
- 12
- 19
1
vote
1 answer
Inner Local Classes in Java
public class Main {
public static void main(String[] args) {
int b=1;
final int c=2;
String s1[] = new String[]{"A","B","C"};
class InnerMain{
int a=5;
…

Furkan
- 117
- 1
- 2
- 6
1
vote
1 answer
Local type as template argument inside not instantiated function
Local type as template argument is forbidden in C++03:
template
struct Foo { };
void Make()
{
struct Unknown {};
Foo foo; // Bad
}
Is there any directives in Standard about checking this rule in case of template is not…

DmitriyH
- 420
- 4
- 15