gpt4 book ai didi

c++ - 我的错误,还是英特尔编译器中的错误? sizeof 非静态成员错误

转载 作者:IT老高 更新时间:2023-10-28 23:21:57 27 4
gpt4 key购买 nike

我相信这段代码:

#include <stdio.h>

struct foo {
char array[1024];
};

int main() {
fprintf(stderr, "sizeof(foo::array): %zd\n", sizeof(foo::array));
}

是有效的 C++。 g++ 使用 -ansi -pedantic 编译它就好了。但是,使用 Intel 的 icc 12.1.3 编译我得到:

error #288: a nonstatic member reference must be relative to a specific object

是我的错误还是 icc 做错了 re: C++ 规范?

最佳答案

这是一个编译器错误,或者编译器是在标准采用此功能之前发布的。

根据 C++ 标准(5.1 主要表达式)

13 An id-expression that denotes a non-static data member or non-static member function of a class can only be used:

— if that id-expression denotes a non-static data member and it appears in an unevaluated operand.

[ Example:
struct S {
int m;
};
int i = sizeof(S::m); // OK
int j = sizeof(S::m + 42); // OK
—end example ]

关于c++ - 我的错误,还是英特尔编译器中的错误? sizeof 非静态成员错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896832/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com