难道又是编译器的问题(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)
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)
...全文
相关推荐
vs2010一些常见的错误以及解决方法汇总 vc++6.0转vs2010时出现的问题的解决方法
如果问题依旧,尝试手动下载并安装缺失的Help文件。从VC++6.0迁移到VS2010时,需要注意的主要问题是编译器和库的不兼容性、项目设置的差异以及新特性的使用。
vs2008与vc6初步编程差别
### VS2008与VC6初步编程差别详解#### 一、编译器环境概述Visual Studio 2008 (简称VS2008) 和 Visual C++ 6.0 (简称VC6) 是两个不同的开发环境
VC中常见问题
**成员列表功能不稳**:如果VC6.0的自动显示成员列表功能不稳定,可以尝试删除扩展名为.ncb的文件,然后重新打开项目,这通常能解决问题。4.
VC常见问题及其解决办法
以上是一些常见的VC++6.0使用过程中遇到的问题及其解决办法。希望这些信息能帮助初学者更好地理解和解决实际开发中遇到的问题。
MFC VC60的outlook风格控件(整理版)
本篇文章将详细介绍如何在VC6.0环境下创建并使用Outlook风格的控件,以及处理编译过程中的常见问题。


