小编sir*_*rg3的帖子

C++静态const通过NULL指针访问

class Foo {
public:
 static const int kType = 42;
};

void Func() {
 Foo *bar = NULL;
 int x = bar->kType;
 putc(x, stderr);
}
Run Code Online (Sandbox Code Playgroud)

这是定义的行为吗?我阅读了C++标准但是找不到任何关于访问静态const值的内容......我已经检查了GCC 4.2,Clang ++和Visual Studio 2010生成的程序集,并且它们都没有执行NULL的解引用指针,但我想确定.

c++ static pointers

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

标签 统计

c++ ×1

pointers ×1

static ×1