Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:12:54+00:00 2026-06-18T04:12:54+00:00

My class declaration begins as follows: template< class P, class B, class comparePosition =

  • 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:12:56+00:00Added an answer on June 18, 2026 at 4:12 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Why following code
When I compile this code in Visual Studio 2005: template <class T> class CFooVector
I am looking at Objective-C and I notice, for example, a class-interface declaration begins
I am facing issue in declaration of inner template class. I have create a
I have the code: // class declaration class Vector3D; // class declaration and definition
the following java class declaration is incorrect: public class BookKeeping<T extends Transaction<K extends Money>>
Whenever a class declaration uses another class only as pointers, does it make sense
Here's what I want the resulting class declaration to look like: public sealed partial
How do I define func outside of the class declaration, below class A{...}; ?
is there any way to reference a class name from within the class declaration?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.