473,473 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Nested class with public access????

I have a small question w.r.t nested class..
I see in many codes nested classes are declared as public..
First, of all my understanding is that you go in for a nested class if
you are sure that this class cannot exist on it's own..
So , generally this should be declared as private so that none can
instantiate this openly..
I need to know the following..
a)Is there any design advantage of having nested class as Public???
class A{
public:
class B{
};
B b;
}

May 21 '07 #1
1 1361
On 21 Maj, 13:34, Nike <pra.ra...@gmail.comwrote:
I have a small question w.r.t nested class..
I see in many codes nested classes are declared as public..
First, of all my understanding is that you go in for a nested class if
you are sure that this class cannot exist on it's own..
So , generally this should be declared as private so that none can
instantiate this openly..
I need to know the following..
a)Is there any design advantage of having nested class as Public???
I'd say it's useful to indicate that a class is (as you said) strongly
connected with another. Consider for example an implementation of a
list:

class List {
public:
struct Node
{
Node* prev;
Node* next;
};

private:
Node* first;
};

However in many cases you might not want to make the implementation
public so you would perhaps make it private. Another use (though not
for classes) is for enums:

class Foo {
public:
enum Type{ One, Two };
void setType(Type);
};

int main() {
Foo f;
f.setType(Foo::Two);
}

--
Erik Wikström

May 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: nobody | last post by:
I just tried to do something and realized I'm not sure of the proper (if there *IS* a proper) way to do it. I'm designing a class with a lot a methods/properties. I would like to group some of...
3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
2
by: newbiecpp | last post by:
Java can declare a static nested class. Does C++ have same thing like? class Outer { public: static class Inner { ... }; .... };
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
7
by: Ryan Shaw | last post by:
I’m having a small problem with inheritance with a hierarchy of classes The example is Class Class Private m_classB as Class Class Class End Clas End Clas
6
by: moondaddy | last post by:
I'm new to c# and am wondering if its possible to access members of a nested class. Can someone please advise? Thanks. class Program { static void Main(string args) { try { Test1 obj =...
2
by: miked | last post by:
I am architecting in a read only class for use in mapping data to a business object. The object makes strong use of nested classes and their ability to access protected fields. The downside is...
5
by: ZikO | last post by:
Hi there. I have a problem. I have created nested classes but don't know how to access to inner classes. I know I can create objects: Hen Object; Hen::Nest ObjectNest; Hen::Nest::Egg...
5
by: Jake K | last post by:
What purpose does nesting a class inside another class typically server? Are there conditions where this would be beneficial? Thanks a lot.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.