Reputation: 103
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 ()? Such kind of types is used in boost::function..
Upvotes: 1
Views: 142
Reputation: 477100
void()
is a function type. void(*)()
is a pointer type. In C++ you cannot have variables of function type, so T t;
doesn't compile when T
is void()
.
Upvotes: 6
Reputation: 27611
The first void() is a function, whereas the second void(*)() is a pointer to a function.
Upvotes: 1
Reputation: 56479
By
C<void ()> c1;
C<void (*)()> c2;
compiler expects you're passing pointer to a function signature. and first one is not a pointer.
Upvotes: 1