I'm having a scope resolution issue. The gnu compiler is trying to
use the "operator function" from derived class rather than from correct
one, the base class.
Expand|Select|Wrap|Line Numbers
- // VecBasis.h file
- template<class T, size_t numDim> class VecBasis {
- protected:
- valarray<T> arr;
- public:
- VecBasis<T, numDim>() : arr(numDim) {}
- VecBasis<T, numDim>(const VecBasis<T, numDim>& v) : arr(numDim)
- {/**/}
- // ...
- VecBasis<T, numDim> operator * (T v) const {/**/}
- };
- // Vec3.h file
- template<class T> class Vec3 : public VecBasis<T, 3> {
- public:
- Vec3<T> () : VecBasis<T, 3>() {}
- T x() const { return VecBasis<T, 3>::arr[0]; } // is the scope
- operator really necessary here?
- // ...
- T operator * (const Vec3<T>& v) {/**/} // here is the problem
- };
- // main.cpp file
- int main()
- {
- Vec3<float> v0;
- v0.operator*(2.0f); // error
- }
.../../src/main.cpp:17: error: no matching function for call toIf I comment out the Vec3::operator*(), the compiler can guess the
'Vec3<float>::operator*(float)'
.../../src/math/Vec3.h:21: note: candidates are: T
Vec3<T>::operator*(const Vec3<T>&) [with T = float]
right operator function (from base class).
Perhaps I could use the explicit keyword (just guessing) to prevent
implicit casting and the compiler would simply ignore the operator from
derived class and use the correct one, but this would give me much more
trouble. Any idea?
One more thing: is that scope resolution operator obligatory? the
compiler complaints if I don't use it.
Thanks :)