On Fri, 23 Jan 2004 12:34:19 -0000, "Alex Tibbles"
<al**********@yahoo.co.uk> wrote:
quick:
struct A
{
template< typename T >
operator[](size_t index)
Did you mean:
T operator[](size_t index)
?
Or
int operator[](size_t index)
perhaps?
{
return vec_[index];
}
std::vector< int > vec_;
};
int main()
{
A a;
float f = a[1]; // doesn't specify template parameter
or
float f = a.operator()< float >(1); // gcc 3.3.2 Debian gives error
"operator[] not defined"
or what?
}
Any clues?
Ignoring the typos and missing headers,
float f = a.operator[]<float>(1);
should compile (it does on my compilers other than GCC). But why make
the operator a template anyway? It means you have to call it with
explicitly specified template parameters...
Tom
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html