这是无效的 C++ 吗?
struct HybridExpression {
RawExpressionElement *ree;
ExpressionNode *en;
};
vector<HybridExpression> hexpression;
hexpression.insert(hexpression.begin() + starti,
(HybridExpression) {NULL, en});
gcc 构建时不会发出警告,但 Visual Studio 2010 甚至不会编译它。
它不喜欢这一点:(HybridExpression) {NULL, en}
struct HybridExpression {
RawExpressionElement *ree;
ExpressionNode *en;
};
vector<HybridExpression> hexpression;
hexpression.insert(hexpression.begin() + starti,
(HybridExpression) {NULL, en});
gcc builds without warning but visual studio 2010 wont even compile it.
It doesnt like this bit: (HybridExpression) {NULL, en}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是使用 C 编程语言中未包含在 C++ 中的一部分,称为“复合文字”。
g++ -ansi
会对此进行诊断,并表示这不是 C++0x 的一部分。
C++0x 兼容语法是
引用 C99 标准,第 6.5.2.5 段:
This is using a part of the C programming language that is not included in C++, it's called "compound literal".
g++ -ansi
will diagnose this, sayingThis is not a part of C++0x.
The C++0x compatible syntax would have been
To quote the C99 standard, paragraph 6.5.2.5:
根据 http://gcc.gnu .org/onlinedocs/gcc-4.1.2/gcc/C_002b_002b-Extensions.html#C_002b_002b-Extensions,您可以在使用 GCC 编译的 C++ 程序中使用 C 扩展(包括 C99 的东西)。
复合文字 是扩展名你实际上正在使用。
According to http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C_002b_002b-Extensions.html#C_002b_002b-Extensions, you can use C extensions (including C99 stuff) in C++ programs compiled with GCC.
Compound literals is the extension you're actually using.
这在当前标准中不是有效的 C++。我认为 GCC 允许这样做是因为有特定于 GCC 的编译器扩展。
This is not valid C++ in the current Standard. I think GCC allows it because of a GCC-specific compiler extension.