D
danilo.horta
Hi folks
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.
When I try to compile the code, it says,
If I comment out the Vec3:perator*(), the compiler can guess the
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
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.
Code:
// 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
}
When I try to compile the code, it says,
.../../src/main.cpp:17: error: no matching function for call to
'Vec3<float>:perator*(float)'
.../../src/math/Vec3.h:21: note: candidates are: T
Vec3<T>:perator*(const Vec3<T>&) [with T = float]
If I comment out the Vec3:perator*(), the compiler can guess the
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