user2319183
user2319183

Reputation: 103

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 ()? Such kind of types is used in boost::function..

Upvotes: 1

Views: 142

Answers (3)

Kerrek SB
Kerrek SB

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

TheDarkKnight
TheDarkKnight

Reputation: 27611

The first void() is a function, whereas the second void(*)() is a pointer to a function.

Upvotes: 1

masoud
masoud

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

Related Questions