gcc-help@gcc.gnu.org
Panos C. C.
godlike_panos_hot@hotmail.com
Mon Jul 12 14:00:00 GMT 2010
I get a very weird error in a simple and pretty straightforward piece of code involving 2 templates. I've found a workaround but its ugly and probably unsafe. Does anyone know what is wrong with the following code. Intel C++ compiler also fails.
Error:
../main.cpp: In function ‘int main()’:
../main.cpp:54: error: no match for ‘operator=’ in ‘niaou = bs.RsrcContainer<Type>::foo [with Type = B]()’
../main.cpp:19: note: candidates are: RsrcPtr<Type>& RsrcPtr<Type>::operator=(RsrcPtr<Type>&) [with Type = B]
Code:
--------------------------------------------------------------------------------
template<typename Type>
class RsrcPtr
{
public:
explicit RsrcPtr(Type* p_ = NULL):
p(p_)
{}
RsrcPtr<Type>& operator=(RsrcPtr<Type> &a)
{
p = a.p;
a.p = NULL;
}
private:
Type* p;
};
template<typename Type>
class RsrcContainer
{
public:
RsrcPtr<Type> foo()
{
RsrcPtr<Type> tmp(new Type);
return tmp;
}
};
class B
{
public:
int x;
};
int main()
{
RsrcContainer<B> bs;
RsrcPtr<B> niaou;
niaou = bs.foo();
return 0;
}
--------------------------------------------------------------------------------
If I replace operator= with this:
template<Type1>
RsrcPtr<Type1>& operator=(RsrcPtr<Type1> &a)
{
p = a.p;
a.p = NULL;
}
I get no error (actually auto_ptr does the same) but its not logical.
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969
More information about the Gcc-help
mailing list