In C language, structures can be defined inside structures, Similarly in C++, we can
have structures or classes defined inside classes. Classes defined within other classes are called nested classes.
A nested class is written exactly in the same way as a normal class. We write its data members, member functions, constructors and destructors but no memory is allocated for a nested class unless an instance of it is created. C++ allows multiple levels of nesting. Importantly, we should be clear about the visibility of the nested class. If a class is nested inside the public section of a class, it is visible outside the outer (enclosed) class. If it is nested in the private section, it is only visible to the members of the outer class. The outer class has no special privileges with respect to the inner class. So, the inner class still has full control over the accessibility of its members by the outer class. Interestingly, the friend operator can be used to declare enclosed class as a friend of inner class to provide access to inner class’s private members. This operator is used in the same way as we use it for other classes that are not nested. We can also make the inner class to access the private members of enclosed class by declaring the inner class as a friend of outer class. The reason of nesting classes within other classes is simply to keep associated classes together for easier manipulation of the objects.
Get free java tutorial, free php tutorials, free c++ tutorials, free asp tutorials and free c sharp tutorials form here
Wednesday, February 8, 2012
Templates
There are two different types of templates in C++ language i.e.’ function templates
and class templates. Before going ahead, it will be sagacious to know what a template
is? You have used a lot of templates in the childhood. There are small scales being
marketed at the stationary shops having some figures on them like circle, a square,
rectangle or a triangle. We have been using these articles to draw these shapes on the paper. We put the scale on the paper and draw the lines with the pencil over that figure to get that shape. These engraved shapes are generally called stencils. But in a way, these are also templates. We may also take these ‘cut-outs’ as sketches. So a template is a sketch to draw some shape or figure. While drawing a special design, say of furniture, we develop a template for this, which is not an actual piece of furniture. We try that its shape should be like the outline. Later,the cut out prepared out of wood in line with the template, is actual piece of furniture. We can think of making a triangular template and then drawing it on a piece of wood and shaping it into a triangle. We can use the same template and put it on a piece of metal and can cut it into a triangle and so on. In a way, that template is allowing us the reuse of a certain shape. This is the concept we are going to try and build on here.
and class templates. Before going ahead, it will be sagacious to know what a template
is? You have used a lot of templates in the childhood. There are small scales being
marketed at the stationary shops having some figures on them like circle, a square,
rectangle or a triangle. We have been using these articles to draw these shapes on the paper. We put the scale on the paper and draw the lines with the pencil over that figure to get that shape. These engraved shapes are generally called stencils. But in a way, these are also templates. We may also take these ‘cut-outs’ as sketches. So a template is a sketch to draw some shape or figure. While drawing a special design, say of furniture, we develop a template for this, which is not an actual piece of furniture. We try that its shape should be like the outline. Later,the cut out prepared out of wood in line with the template, is actual piece of furniture. We can think of making a triangular template and then drawing it on a piece of wood and shaping it into a triangle. We can use the same template and put it on a piece of metal and can cut it into a triangle and so on. In a way, that template is allowing us the reuse of a certain shape. This is the concept we are going to try and build on here.
Hi everyone
Hellow everyone........welcome to my blog. I am going to share some programming tutorials here with you. They are totally free and you can learn and share with your friends too. If you have any suggestions, please mail me and if you need any tutorial that I haven't shared here yet, feel free to ask and I'll try to provide that here. So Lets start learning how to program.
Subscribe to:
Posts (Atom)