Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

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{

On 21 Maj, 13:34, Nike <pra.ra@gmail.com> wrote:

> 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 Wikstrm
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc