情况描述:
在任何管理器(Debug或Release,x64或x82等)环境下编译均报错,在配置属性中无论怎么修改各设置均报错,但报错内容指出了出错代码块的位置
出错代码摘要:
//用宏定义了一些常量
#define X 0
#define Y 1
#define R 2
//圆形类(仅报错部分摘要)
template<typename NumType> //template模板是为了便于以后使用时可以选择用int或float或double
class Circle
{
protected:
NumType m_x, m_y, m_r; //圆心坐标、半径
public:
//构造函数等略去
/*......*/
//出错函数:
//成员访问接口
NumType& operator[](char index);
const NumType& operator[](char index) const; //index的取值开头的那些常量
};
//成员函数定义:
//访问成员
template<typename NumType>
NumType& Circle<NumType>::operator[](char index)
//下文称此函数为operator[]
{
switch (index)
{
case X:
case'X':
case'x':
return m_x;
case Y:
case'Y':
case'y':
return m_y;
case R:
case'R':
case'r':
default:
return m_radius;
}
} //报错指出的行列号在这个位置
//访问成员(返回常量)
template<typename NumType>
const NumType& Circle<NumType>::operator[](char index) const
//下文称此函数为const operator
{
switch (index)
{
case X:
case'X':
case'x':
return m_x;
case Y:
case'Y':
case'y':
return m_y;
case R:
case'R':
case'r':
default:
return m_radius;
}
}
解决过程:利用注释来