Reputation: 423
I'm trying to compile a project which uses OpenCV C++ code in Xcode.
template<typename _Tp> inline MatND_<_Tp>& MatND_<_Tp>::operator = (const MatND& m)
{
if( DataType<_Tp>::type == m.type() )
{
Mat::operator = (m);
return *this;
}
if( DataType<_Tp>::depth == m.depth() )
{
return (*this = m.reshape(DataType<_Tp>::channels));
}
CV_DbgAssert(DataType<_Tp>::channels == m.channels());
m.convertTo(*this, DataType<_Tp>::type);
return *this;
}
Here it gives me a compiler error "Call to non-static member function without an object argument" on line "Mat::operator = (m);"
The code is not corrupt, I verified it here.
Another interesting this is that, if I choose the compiler as LLVM GCC 4.2 then the code works fine, but I get this error when compiling with Apple LLVM compiler 3.2. I need to compile with Apple LLVM compiler since compiling with GCC is creating other problems.
What is the issue here?
Upvotes: 1
Views: 1737
Reputation: 64308
You need to use
this->Mat::operator = (m);
When you are inside a templated member function, the compiler doesn't know what your base class is. It just looks like you are trying to call a static member function, but Mat::operator=() isn't static, so it gives you that error. By using this->Mat::operator=(m), the compiler now knows that you are actually trying to call a non-static member function.
With older compilers, there was less checking of templates when they were first encountered. They were largely just stored as a big sequence of tokens and only when the template was instantiated was any checking done. The C++ standard now requires that templates have a certain amount of checking done before they are instantiated, which makes certain tricks like this necessary.
Upvotes: 2