Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected type-specifier C++ template class

Tags:

c++11

So I am trying to implement a Vector class.

I am getting the error "expected type-specifier before '[' token" in my 'at' function, as shown below:

T Vector<T>::at(unsigned i){
    return operator[i]; 
}

I have tried:

return this->operator[i];

and

(*this).operator[i];

but to no avail. Any ideas?

like image 888
user3150552 Avatar asked Sep 15 '26 03:09

user3150552


1 Answers

The syntax would be

return this->operator[](i);

or more canonically

return (*this)[i];
like image 138
Cory Kramer Avatar answered Sep 16 '26 18:09

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!