nested classes in c++

consider the following classes:
1.book:holds the properties like book_id,title,author,publisher,category etc…
2.publisher:holds the properties like name,id,address etc…
3.author:holds the properties like name,id,address etc…
4.category:holds the properties like title,id,etc…

consider the following notes:
1.consider relevant behaviors for every class
2.assume exactly one author and one publisher for each book
3.demonstrate the following concepts by implementing suitable behaviors:
i)parametrized constructor and destructors
ii)nested classes:find and implement suitable outer class and classes
iii)array of objects:create array of book class objects
iv)friend functions:
1.find the total number of book published by a specified publisher
2.list all the book of a specified author.

In c++ or in any other programming language the nested class have same work we declared within the scope of another class and nested class can access to all names (like private, protected ). And the best thing I really like about nested class is this is cool for hiding implementation details. Case Study Writing Help Online

If declared a class within the scope of another class such class is called a “nested classes” and you can use nested class within the scope of the enclosing class, and I refer you read and learn abstract class chapter to learn in depth about the nested class.

Nested Classes in C++
A nested class is a class which is declared in another enclosing class. A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules shall be obeyed.

For example, program 1 compiles without any error and program 2 fails in compilation.

Program 1

#include

using namespace std;

/* start of Enclosing class declaration */

class Enclosing {

int x;

/* start of Nested class declaration */

class Nested {

  int y;   

  void NestedFun(Enclosing *e) {

    cout<<e->x;  // works fine: nested class can access


                 // private members of Enclosing class

  }    

}; // declaration Nested class ends here

}; // declaration Enclosing class ends here

int main()

{

}

Program 2

#include

using namespace std;

/* start of Enclosing class declaration */

class Enclosing {

int x;

/* start of Nested class declaration */

class Nested {

  int y;   

}; // declaration Nested class ends here

void EnclosingFun(Nested *n) {

    cout<<n->y;  // Compiler Error: y is private in Nested

}

}; // declaration Enclosing class ends here

int main()

{

}

Why nested class?

Nested classes are cool for hiding implementation details

List:

class List

{

public:

    List(): head(NULL), tail(NULL) {}

private:

    class Node

    {

          public:

              int   data;

              Node* next;

              Node* prev;

    };

private:

    Node*     head;

    Node*     tail;

};

Here I don’t want to expose Node as other people may decide to use the class and that would hinder me from updating my class as anything exposed is part of the public API and must be maintained forever. By making the class private, I not only hide the implementation I am also saying this is mine and I may change it at any time so you can not use it.

source- Nested Classes in C++ - GeeksforGeeks

Why would one use nested classes in C++? - Stack Overflow

Those students who take proper classes to gain some knowledge implementing suitable books by specified author. Assignments Help UK writers with full assistance.

C++ is the most useful language in programming but first, you need to learn start from basic programming and then come to advanced Found.com.pk | seo services Pakistan here I learn all these languages and now I start working as an employee and here you can find all your solution.

There is no doubt c++ is the base of programming. If you have a good command of c++. you will be expert of programming. Classes of c++ in deeper but once you got practice of this, you will habitual of these classes.
I’m a web designer of an web design toronto company & i often faced these types of c++ nested classes.

Thanks for this article. It contains the information i was searching for and you have also explained it well. We are also an assignment writing help provider. So, the students struggling to write their college assignments can opt for our online assignment help and can get a quality assignment written from us.

Develop and test thoroughly the magnificence Complex containing proper provide Do my assignment, reproduction constructor and destruct or functions in addition to appropriate set and get functions. The magnificence should additionally provide. Thank you for your provide.

what is this about ? what do you except from us ?

1 Like