3

I've found this code in the project I'm working:

template<typename T>
class SomeClass
{
};
typedef SomeClass<void(void)> SomeType;

What means <void(void)> construction? Can you please explain in a simple sample how a construction like this one may be used?

Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211

2 Answers2

5

It means that the type parameter is a function type (note, not a function pointer, but a function type) that takes no parameters, and returns no value.

You can even define function parameters in such a way:

void f (void(void));

That will decay to a function pointer when passed (just like an array parameter decays to a pointer).

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
  • Do you know some articles about this feature? I can't find any good references for it. Thanks! – Mircea Ispas Dec 12 '12 at 15:56
  • Well, there is a very good question and answer about it here on [SO](http://stackoverflow.com/questions/4642079/function-signature-like-expressions-as-c-template-arguments). I couldn't find anything else though, sorry. – StoryTeller - Unslander Monica Dec 12 '12 at 16:11
  • Thanks, I've found header and trying this in code as a very nice reference:) I'm starting to understand the concept. – Mircea Ispas Dec 12 '12 at 16:21
1

T here is a type of function that returns nothing and takes no arguments.

Marlon
  • 19,924
  • 12
  • 70
  • 101