Questions tagged [nested-class]

In Object Oriented programming, a class defined inside another class. Also called "inner class".

In there are times when a class A is used only as a component of another class B and should not be instanced outside B. In those cases proper encapsulation suggest defining that class as a nested or inner class.

Several languages support this feature (C++, Java, .Net languages, D, python, for example) although with minor differences in where nested classes can be defined, how can they be used; and some languages support more than one variety of nested class.

574 questions
-1
votes
2 answers

Using Nested Classes Instead of Multiple Inheritance, C++

I am trying to use nested classes instead of multiple inheritance. I am following the recommendations from the book but I keep getting an error in the constructor. Basically, Person is the grandfather, Student and Employee are the Parent and…
-1
votes
1 answer

Access friend class's private member

I'm trying to write a console application like Twitter. User and UserList classes including each other. I'm trying to access to following user's followers. UserList class is used for linked list. //User.h #pragma once #include #include…
-1
votes
1 answer

How to manipulate variables in deep class

I just started to learn Java and i think this a very basic question but i didn't find the right answer yet so i try in here. I just want to show in my console the names and descriptions of some animals, but i don't know how to manipulate variables…
Dinodzo
  • 31
  • 1
  • 6
-1
votes
3 answers

How to create an array of references to a class?

The title might be a bit misleading but I can't think of another way to describe it. Let me just show you an example: class SomeClass { class Foo { class Bar { int things = 57; String five = "things"; } class OtherBar { …
-1
votes
1 answer

How do I use a function of another class inside a class?

So I have classes that I would like to work together. My first two establish a connection to the database: dbconn.php
-1
votes
1 answer

Nested class from a string

I want to call a method on a class in the namespace of Publishers, such as Publishers::Vk, where the nested part is expressed as a string like provider_name = 'Vk'. I did something like that: send("Publishers::#{provider_name}.new(#{@photo})") I…
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
-1
votes
2 answers

VS2008 C++ debugger seems unable/unwilling to look inside instances of structs defined within a function. How are people debugging such code?

VS2008 C++ debugger seems unable/unwilling to look inside instances of structs defined within a function when these instances (or references to) are declared in a different scope to the one where the nested struct is defined (such as a for loop).…
OldSchool
  • 459
  • 1
  • 3
  • 14
-1
votes
1 answer

nested static class method cannot be accessed by outer class?

I created a nested static class like this: public class OuterClass { public static class NestedClass { public static String getName() { //Some stuff return "Name"; } } //Now am not able to call the method *getName()*…
noMAD
  • 7,744
  • 19
  • 56
  • 94
-1
votes
2 answers

Generic repository, nested class mapping

I'm trying to generate a Generic Repository. So far, so good. But I get the same error as somebody else posted before: Mapping to a nested class The problem is that I am apparently trying to map a nested class. How can I fix this, so I do not map a…
1408786user
  • 1,868
  • 1
  • 21
  • 39
-1
votes
1 answer

Typedef of a nested class

Is this the correct way to typedef an inner class in C++? class Foo { public: struct A { typedef bool Type; }; struct B { typedef int Type; }; typedef struct Foo::nested; }; The code compiles under …
Olumide
  • 5,397
  • 10
  • 55
  • 104
-2
votes
1 answer

Linked-list with nested classes: how can I use nested class type before it is declared?

Ok, here's my problem, if a problem it is at all. I'm building a linked list. This linked list is composed of elements in form of a class. Thus I have a class called, let's say, linked_list and a nested one called just node. Obviously, the main…
-2
votes
1 answer

Nested classes java

I have the following code: public class A { private class B { public String a = ""; public B(String a) { System.out.println("hello"); this.a = a; } } public A() { …
John Doe
  • 169
  • 1
  • 8
-2
votes
1 answer

overload square bracket operator with private nested class

I want to overload the square bracket operator [] using a private nested class to differentiate between v[i] = val and val = v[i]
-2
votes
2 answers

is a nested class a singleton in java

In Java a nested class is an inner class that is declared static. E.g.: class Basic{ public static class NestedClass{}; } I am wondering if a nested class is a singleton by default, or if I may create a list of instances such as class Basic{ …
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
-2
votes
3 answers

Java - nested class and array - Exception in thread "main" java.lang.NullPointerException

I'm new to Java and I'm implementing a class (CenterTable) that contains a nested class (CenterData). Inside the enclosing class, I want to create an array of type CenterData. The code can be seen below: public class CenterTable { public class…
1 2 3
38
39