0

My class declaration begins as follows:

template< 
    class P, 
    class B, 
    class comparePosition = compareHorizontal< P >
>
class BlahBlah  { ...

where compareHorizontal is a template function. When I attempt to compile, clang spits out

[...]/entity.hpp:57:33: error: type name requires a specifier or qualifier
        class comparePosition = compareHorizontal< P >
                                ^

[...]/entity.hpp:57:33: error: C++ requires a type specifier for all declarations
        class comparePosition = compareHorizontal< P >
                                ^~~~~~~~~~~~~~~~~

(and a whole lot of other errors on the same line).

If I just remove the default template parameter, leaving all else intact, it compiles just fine. So I wonder, how would I use a function template as a default argument, if that's even possible? Or would I be better off just making a functor class with an operator() that calls compareHorizontal and use that instead?

3
  • compareHorizontal is a template function or template class? Commented Feb 1, 2013 at 12:40
  • @billz - it's a template function Commented Feb 1, 2013 at 12:41
  • Then that should answer your question, a function is not a class (or a type at all), and that's what you expect with class comparePosition. Commented Feb 1, 2013 at 12:47

1 Answer 1

1

I think the reason is that the template function is not a type. It is a specific value if you think of it, the type of the function goes something like this:

  template<
       class P,
       class B,
       class C=bool (*)(P&)
   >
   class BlahBlah  {
   };

and it compiles. It is as if you said class C=5; this also will not compile, because 5 is not a type. I suggest you use a struct in such case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.