 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Aff@n Guest
|
Posted: Mon Aug 28, 2006 9:10 am Post subject: overloading operator [] |
|
|
hi,
i wold like to ask, why is it when overloading operator[] we send int
value is there any way around?.
e.g.
class abc
{
protected:
int *a;
private:
int operator[](int );
};
int abc::operator[](int x)
{
int z;
z=a[x];
return z;
}; |
|
| Back to top |
|
 |
Kai-Uwe Bux Guest
|
Posted: Mon Aug 28, 2006 9:10 am Post subject: Re: overloading operator [] |
|
|
Aff@n wrote:
| Quote: | hi,
i wold like to ask, why is it when overloading operator[] we send int
value is there any way around?.
e.g.
class abc
{
protected:
int *a;
private:
int operator[](int );
};
int abc::operator[](int x)
{
int z;
z=a[x];
return z;
};
|
In your case, operator[] takes an int argument because and only because you
defined it that way. You could as well do:
class abc
{
protected:
int *a;
private:
int operator[]( std::size_t );
};
int abc::operator[]( std::size_t x)
{
int z;
z=a[x];
return z;
};
Best
Kai-Uwe Bux |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|