Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help overloading [] 1

Status
Not open for further replies.

iggyentity

Programmer
Apr 3, 2002
2
IE
When i overload the operator [] for a vector is there any better way of using it inside the class definition itself ie.

Class Dataset
......

int& operator[](int x){
return vector[x];
}

bool compare(int position, int variable){
return operator[](position)==variable // is there any
//better way than
// this
}
 
Iggy,

I assume that you are trying to compare the position-th value in the vector with the content of variable. First off, where is the vector that you are trying to subscript?



Class Dataset
{
...

int& operator[](int x)
{ return vector[x]; }

bool compare(int position, int variable)
{ return (*this)[position]==variable; }
...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top