Small yet annoying (template) overloading problem
Posted on 2003-11-17
I'm constantly getting this compiler error and there are workarounds, but I prefer readability above those workarounds :-)
I will give you a simplified version of the code:
template <typename T>
operator T * () const throw()
T& operator  (UINT uPos) const throw()
T * m_buffer;
class CString : protected CBuffer<TCHAR>
using CBuffer<TCHAR>::operator ;
void Empty() throw()
(*this) = '\0';
This code gives me this error:
c:\Weltevreden Framework\Source\Utility.hpp(477) : error C2666: 'Weltevreden::Utility::CBuffer<T>::operator`'' : 2 overloads have similar conversions
c:\Weltevreden Framework\Source\Utility.hpp(139): could be 'TCHAR &Weltevreden::Utility::CBuffer<T>::operator (UINT) throw()'
or 'built-in C++ operator[(TCHAR , int)'
while trying to match the argument list '(Weltevreden::Utility::CString, int)'
Can easily be solved by either commenting out the T * operator from CBuffer or by using an "elementAt" function instead of the "operator ". In this case it may even be better readable, but I still prefer to have the "operator " working and it gives the same error if I use it elsewere (also want to keep the T * operator by the way :-)). The strange thing is that I don't use the type casting operator in the CString class (ie I don't do this: "using CBuffer<TCHAR>::operator T * ();"). So basically the compiler should be ignoring that operator all together as I use the CBuffer as a protected subclass shouldn't it?
Well either way, if you have an idea on how to solve this (or some suggestive imput) please share :-)