【发布时间】:2013-09-22 21:33:04
【问题描述】:
基本上,我想知道为什么编译器会拒绝ptr2 声明:
int main() {
// this one works
decltype(void())* ptr1;
// this one does not
decltype(void{})* ptr2;
}
如果您认为ptr1 是函数指针,请查看this code:
#include <iostream>
using namespace std;
template <class T>
void f(T t) {
cout << __PRETTY_FUNCTION__ << endl;
}
int main() {
decltype(void())* ptr;
f(ptr);
}
输出是void f(T) [with T = void*]。
【问题讨论】:
-
void{}应该是什么? -
@chris 和
void()一样,不管是什么。 -
“这个有效” ...“这个无效”——看起来就是这样。
-
@KeithThompson 但是为什么有任何区别呢?
-
@jeffamaphone 为什么要删除
c++标签?我的意思是,c++11仍然是c++,对吧?..