- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
考虑以下代码:
template<int* a>
class base {};
int main()
{
base<(int*)0> test;
return 0;
}
Comeau 和 MSVC 都可以毫无问题地编译它(除了 Comeau 警告未使用的变量),而 GCC 在 base<(int*)0> test;
上失败行,说明
In function `int main()': a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
template argument 1 is invalid
它到底在提示什么?谁是对的——这段代码应该编译吗?值得注意的是,我的 GCC 版本非常旧 (3.4.2),所以这可能与它有关。谢谢。
最佳答案
来自draft standard (强调):
14.1.3 A non-type template-parameter shall have one of the following (option- ally cv-qualified) types: ... --pointer to object, accepting an address constant expression desig- nating a named object with external linkage, ...
显然,用空指针实例化模板是不合法的,因为空指针不指向“具有外部链接的命名对象”。
关于c++ - 将指针转换为模板参数 : Comeau & MSVC compile, GCC 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1418019/
为什么我们不能使用这样的东西 struct { int bar; } Foo; int main() {} 在 C++ 模式的 Comeau 编译器中,而在 C 模式下我们可以吗? "Come
我正在尝试使用 SFINAE 来检测类是否具有采用特定类型的重载成员函数。我的代码似乎可以在 Visual Studio 和 GCC 中正常工作,但无法使用 Comeau 在线编译器进行编译。 这是我
考虑以下测试1代码 struct A { private: class face; friend class face; }; struct A::face {}
到目前为止,我一直在使用 gcc、g++ 进行 C、C++ 应用程序开发,并且发现它非常棒。但是浏览 Stack Overflow 我发现许多成员表示 Comeau 编译器中的错误报告比任何其他编译器
考虑以下代码: template class base {}; int main() { base test; return 0; } Comeau 和 MSVC 都可以毫无问题地编译
这是测试代码 template void f() { T t; t.f(0); //compiles even without the "template" keyword, what am
我有几个关于 C++ 编译器的问题 C++ 编译器是否需要 one-pass compiler ?标准是否在任何地方谈论它? 特别是 GCC 是一次性编译器吗?如果是,那么为什么它会在 this ex
我是一名优秀的程序员,十分优秀!