B
Bangalore
Hi all,
I have a problem in accessing elements using overloaded operator [].
Consider,
const int SIZE=10;
int FALSE=0;
class Array
{
private:
int x[SIZE];
public:
//overloading []
int& operator [] (int index)
{
if ( index < 10 )
return x;
else
return FALSE;
}
};
class Base
{
private:
int i;
Array *p[2];
public:
Base ()//Here how to initiaze pointer with initialization
list
{
for(i=0; i<SIZE; i++)
//here how to assign value to array x{SIZE] in
class Array
}
void Display()
{
for(i=0; i<SIZE; i++)
//here also how show value
}
};
int main()
{
Base b;
b.Display();
}
I can directly use x[SIZE] in class Base, but with this object size of
Base will
increase drastically if the value of SIZE takes higher value , so I
want to keep size of Base as minimum as possible.
Plz , clarify me with your suggestions,
Thanks in advance
Bangalore
I have a problem in accessing elements using overloaded operator [].
Consider,
const int SIZE=10;
int FALSE=0;
class Array
{
private:
int x[SIZE];
public:
//overloading []
int& operator [] (int index)
{
if ( index < 10 )
return x;
else
return FALSE;
}
};
class Base
{
private:
int i;
Array *p[2];
public:
Base ()//Here how to initiaze pointer with initialization
list
{
for(i=0; i<SIZE; i++)
//here how to assign value to array x{SIZE] in
class Array
}
void Display()
{
for(i=0; i<SIZE; i++)
//here also how show value
}
};
int main()
{
Base b;
b.Display();
}
I can directly use x[SIZE] in class Base, but with this object size of
Base will
increase drastically if the value of SIZE takes higher value , so I
want to keep size of Base as minimum as possible.
Plz , clarify me with your suggestions,
Thanks in advance
Bangalore