难道又是编译器的问题(VC6.0),帮忙看一下这个重载操作符为何报错?

showming showming 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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)
...全文
评论 4
收藏 已收藏
分享
返回顶部
showming
C++ 语言 65,214 成员 250,514 内容