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 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
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
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?
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
?
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
by: subramanian100in |
last post by:
Consider the program
#include <iostream>
using namespace std;
class Test
{
public:
Test(Test_int c_value)
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |