难道又是编译器的问题(VC6.0),帮忙看一下这个重载操作符为何报错?
#include<iostream>
using namespace std;
template<class T> class Handle
{
T *ptr;
int *use;
public:
Handle(const T *):ptr=new T(t),use=new int(0){}
Handle(const Handle &);
Handle& operater=(const Handle& );
T& operater*(const Handle *) const;
T* operater&(const Handle &) const;这三行报错!
~Handle();
};
/*template<class T> Handle<T>::Handle(const Handle &rhs)
{
ptr=rhs.ptr;
*use++;
}
template<class T> Handle<T>& Handle<T>::operater=(const Handle &rhs)
{
*rhs.use++;
if(!*use)
{
delete ptr;
}
ptr=rhs.ptr;
*use--;
use=rhs.use;
}
template<class T> T& Handle<T>::operater*(const Handle *pt) const
{
return pt->*ptr;
}
template<class T> T* Handle<T>::operater&(const Handle &pt) const
{
return pt.ptr;
}
template<class T> Handle<T>::Handle ~Handle()
{
if(--*use)
{delete ptr;delete use;}
}
*/
void main()
{
}
报错信息:--------------------Configuration: handle - Win32 Debug--------------------
Compiling...
handle.cpp
C:\code\handle\handle.cpp(12) : error C2059: syntax error : ';'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(12) : error C2238: unexpected token(s) preceding ';'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(13) : error C2143: syntax error : missing ';' before '*'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(13) : error C2226: syntax error : unexpected type 'Handle<T>'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(13) : error C2238: unexpected token(s) preceding ';'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(14) : error C2143: syntax error : missing ';' before '&'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(14) : error C2372: 'operater' : redefinition; different types of indirection
C:\code\handle\handle.cpp(13) : see declaration of 'operater'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(14) : error C2226: syntax error : unexpected type 'Handle<T>'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
C:\code\handle\handle.cpp(14) : error C2238: unexpected token(s) preceding ';'
C:\code\handle\handle.cpp(17) : see reference to class template instantiation 'Handle<T>' being compiled
Error executing cl.exe.
handle.obj - 9 error(s), 0 warning(s)