[英]Difference in template arguments C<void ()> and C<void (*)()>
I don't understand difference between template arguments 我不了解模板参数之间的区别
template <class T>
class C
{
T t;
};
void foo()
{
C<void ()> c1; //isn't compiled
C<void (*)()> c2;
}
What is the type void ()? 什么是void()类型? Such kind of types is used in boost::function..
此类类型用于boost :: function ..
void()
is a function type. void()
是函数类型。 void(*)()
is a pointer type. void(*)()
是指针类型。 In C++ you cannot have variables of function type, so T t;
在C ++中,不能有函数类型的变量,因此
T t;
doesn't compile when T
is void()
. 当
T
为void()
时不编译。
By 通过
C<void ()> c1;
C<void (*)()> c2;
compiler expects you're passing pointer to a function signature. 编译器期望您将指针传递给函数签名。 and first one is not a pointer.
第一个不是指针。
第一个void()是一个函数,而第二个void(*)()是一个指向函数的指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.