小编vin*_*ntp的帖子

范围解析运算符和常量

我们来看下面的代码:

#include <string> // std::string    
using namespace std;
int main() {
  //const::int i = 42;       -> Error: "expected id-expression before 'int'"
  const::string str = "Foo"; // No error: why?
}
Run Code Online (Sandbox Code Playgroud)

为什么这段代码会编译?当XXX是基本类型时,错误"预期在XXX之前的id-expression"出现.

const::char c = 1;   // error: expected id-expression before 'char'
const::double d = 2; // error: expected id-expression before 'double'
const::float f = 3;  // error: expected id-expression before 'float'
const::bool b = 4;   // error: expected id-expression before 'bool'
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
121
查看次数

标签 统计

c++ ×1