473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Class defined Inside a Class

Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}
};

Thanks
Pallav
Nov 20 '08 #1
6 4226
On Nov 20, 12:22 pm, Pallav singh <singh.pal...@gmail.comwrote:
Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}

};

Thanks
Pallav
It is matter of object properties, abstraction and encapsulation.

Like in case of iterator design, iterator class is usually defined
inside container class because this iterator specific to container
class object. This is very general example. There are so many complex
example. I suggest you to study OO design patterns.

--
Daya
Nov 20 '08 #2
Pallav singh wrote:
Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}
};
IMHO it is better to make interfaces simple (see
http://en.wikipedia.org/wiki/KISS_principle), and not do this.

If you have such class in the private part, better move it to the
anonymous namespace (off course in the cpp file).

If you have it in the public part, create a new namespace, and move it there
Nov 21 '08 #3
anon wrote:
Pallav singh wrote:
>Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}
};

IMHO it is better to make interfaces simple (see
http://en.wikipedia.org/wiki/KISS_principle), and not do this.

If you have such class in the private part, better move it to the
anonymous namespace (off course in the cpp file).

If you have it in the public part, create a new namespace, and move it
there
To pick up the iterator example, how would you suggest to do that?

Nov 21 '08 #4
Rolf Magnus wrote:
anon wrote:
>Pallav singh wrote:
>>Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}
};
IMHO it is better to make interfaces simple (see
http://en.wikipedia.org/wiki/KISS_principle), and not do this.

If you have such class in the private part, better move it to the
anonymous namespace (off course in the cpp file).

If you have it in the public part, create a new namespace, and move it
there

To pick up the iterator example, how would you suggest to do that?
Whats wrong with it?

Is this ok :
http://www.cplusplus.com/reference/m.../iterator.html
?
Nov 21 '08 #5
anon wrote:
Rolf Magnus wrote:
>anon wrote:
>>Pallav singh wrote:
Hi

when we should have Class defined Inside a Class ? can any one give me
explanation for it ?
Does it is used to Hide some information of Class Data-Member and
Function from friend class?

class A : public B
{
private:
class C : public D::C1
{
DataType data1;
Function_1( ){ }
};
private:
friend class E;
DataType data2;
Function_2( ){}
};
IMHO it is better to make interfaces simple (see
http://en.wikipedia.org/wiki/KISS_principle), and not do this.

If you have such class in the private part, better move it to the
anonymous namespace (off course in the cpp file).

If you have it in the public part, create a new namespace, and move it
there

To pick up the iterator example, how would you suggest to do that?

Whats wrong with it?
I'm thinking e.g. about the iterator for std::vector, which is defined within
std::vector, so it's then std::vector::iterator. How would you name the
iterator type belonging to std::vector instead? And how would that
additional namepace come into play?
Is this ok :
http://www.cplusplus.com/reference/m.../iterator.html
?
Well, that's an iterator for simple arrays, but usually, an iterator type
belongs to a specific class.

Btw: The example on that page seems to contain an error:

myiterator& operator++() {++p;return *this;}
myiterator& operator++(int) {p++;return *this;}

That doesn't look right. The second operator++ is supposed to return the
previous value of *this, not the new one.

Nov 21 '08 #6
Rolf Magnus wrote:
anon wrote:
>>To pick up the iterator example, how would you suggest to do that?
Whats wrong with it?

I'm thinking e.g. about the iterator for std::vector, which is defined within
std::vector, so it's then std::vector::iterator. How would you name the
iterator type belonging to std::vector instead? And how would that
additional namepace come into play?
This is from the gcc "vector" header:

************************************************** ***********
namespace __gnu_debug_def
{
template<typename _Tp,
typename _Allocator = std::allocator<_Tp
class vector
: public _GLIBCXX_STD::vector<_Tp, _Allocator>,
public __gnu_debug::_Safe_sequence<vector<_Tp, _Allocator
{
// some stuff

public:

typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,vector>
iterator;
typedef __gnu_debug::_Safe_iterator<typename
_Base::const_iterator,vector>
const_iterator;
************************************************** ***********

So, why are you saying the iterator is defined within the vector class?

>Is this ok :
http://www.cplusplus.com/reference/m.../iterator.html
?

Well, that's an iterator for simple arrays, but usually, an iterator type
belongs to a specific class.
Do you have an example? Explaining how the iterator is defined within
the vector class would do :)
Btw: The example on that page seems to contain an error:

myiterator& operator++() {++p;return *this;}
myiterator& operator++(int) {p++;return *this;}

That doesn't look right. The second operator++ is supposed to return the
previous value of *this, not the new one.
Correct.
Nov 21 '08 #7

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
5
by: ganesh.gella | last post by:
Hi All, Wanted to make sure on this, I have some functions for which I am providing the definition inside the class definition. (As these are very small functions like get and set). Do i...
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
19
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works"...
1
by: ypjofficial | last post by:
Hi all, what's difference does it make when we define the member function inside and outside a class? I am using vc7. when i define the member functions outside a class with the scope...
4
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to...
4
by: subramanian100in | last post by:
Consider the program #include <iostream> using namespace std; class Test { public: Test(Test_int c_value)
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.