[Tuxcpprogramming] Accessing operator[] within a class
Mark Phillips
mark at austrics.com.au
Mon Jul 9 13:43:49 UTC 2001
Hi,
The vector class, provided by the Standard Template
Library overloads the operator[]. I want to define
a new version of vector using inheritance, but
with a new method of accessing elements introduced.
It should be something like this:
class myVector: public vector<int> {
int table(int row, int col) const {
return [row*10+col];
}
Now this wouldn't actually compile because
I suspect the syntax "return [row*10+col]"
is wrong. I simply want it to return the
element of the vector in position
"row*10+col" but I don't know how to do this.
I have tried the following:
return vector::[row*10+col];
return vector<int>::[row*10+col];
return vector::operator[](row*10+col);
and a few more variations besides, but nothing
seems to work. Could someone please tell me
the correct way to do it.
Thanks,
Mark.
More information about the tuxCPProgramming
mailing list