下面的代码在vc6和vc2008中都无法通过编译,太奇怪了!
class CBluetooth{
protected:
int BluetoothStatus;
public:
static const int NO_ERROR; static const int HARDWARE_NOT_DETECTED;
static const int HARDWARE_RESET_FAILED;
static const int DRIVER_NOT_INSTALLED;
}
const int CBluetooth::NO_ERROR = 0;const int CBluetooth::HARDWARE_NOT_DETECTED = 1;
const int CBluetooth::HARDWARE_RESET_FAILED = 2;
const int CBluetooth::DRIVER_NOT_INSTALLED = 3;错误信息是:
error C2059: syntax error : 'constant' main.cpp
error C2238: unexpected token(s) preceding ';' main.cpp
error C2589: 'constant' : illegal token on right side of '::' main.cpp
class CBluetooth{
protected:
int BluetoothStatus;
public:
static const int NO_ERROR; static const int HARDWARE_NOT_DETECTED;
static const int HARDWARE_RESET_FAILED;
static const int DRIVER_NOT_INSTALLED;
}
const int CBluetooth::NO_ERROR = 0;const int CBluetooth::HARDWARE_NOT_DETECTED = 1;
const int CBluetooth::HARDWARE_RESET_FAILED = 2;
const int CBluetooth::DRIVER_NOT_INSTALLED = 3;错误信息是:
error C2059: syntax error : 'constant' main.cpp
error C2238: unexpected token(s) preceding ';' main.cpp
error C2589: 'constant' : illegal token on right side of '::' main.cpp
解决方案 »
- 显示jpg图片最快的方式
- vc中如何用ado操作excel
- 如何实现倒计时的对话框
- **************彩票中奖50,庆贺之~*****************
- 在添加类时怎么找不到CInternetSession这个类(vc6)。它是基本类么。
- 一个关于CoCreateInstance的问题--------在线等!
- 在文本框CEdit里面怎么动态移动光标的位置?
- 急征2K下取主板序列号的方法
- 希望VC高手们能给我一写赐教!
- 我自己向工作区中添加已有的类(***.h和***.cpp),但我想修改这个类时,在classwizard中没有,怎么解决?谢谢!
- 怎么hook writefile,readfile最好贴一段原代码
- win32窗口控制的基本
{
public:
static const int xxx = 1234;
static int yyy;
};
int test::yyy=5678;int main()
{
test x;
return 0;
}
2. NO_ERROR 是已经定义的宏
class CBluetooth{
protected:
int BluetoothStatus;
public:
static const int NO_ERRORS;
static const int HARDWARE_NOT_DETECTED;
static const int HARDWARE_RESET_FAILED;
static const int DRIVER_NOT_INSTALLED;
};const int CBluetooth::NO_ERRORS = 0;
const int CBluetooth::HARDWARE_NOT_DETECTED = 1;
const int CBluetooth::HARDWARE_RESET_FAILED = 2;
const int CBluetooth::DRIVER_NOT_INSTALLED = 3;
即static const int HARDWARE_NOT_DETECTED;
而对于 int BluetoothStatus;应该在构造函数内,或者定义处进行赋值。
const int CBluetooth::NO_ERROR = 0;const int CBluetooth::HARDWARE_NOT_DETECTED = 1;
const int CBluetooth::HARDWARE_RESET_FAILED = 2;
const int CBluetooth::DRIVER_NOT_INSTALLED = 3;
class CBluetooth{
protected:
int BluetoothStatus;
} 你定义的是const变量当然是没有办法改变值了阿!
如果定义成const就像我所说的这样定义,如果不是用const定义可以使用楼上的方法
原本就有的常量NO_ERROR当静态变量,唉...我想怎么语法都对还是出错
改名以后一切正常,谢谢大家!