This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
gcc-help@gcc.gnu.org
- From: "Panos C. C." <godlike_panos_hot at hotmail dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 12 Jul 2010 16:57:31 +0300
- Subject: gcc-help@gcc.gnu.org
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