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 8061705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:25:41+00:00 2026-06-05T10:25:41+00:00

I was following template class restriction , but ran into errors in gcc: error:

  • 0

I was following template class restriction, but ran into errors in gcc:

error: multiple types in one declaration

error: declaration does not declare anything

It compiles if I remove the enable_if block. Can anybody explain if I am missing something?

template<class A, class B, class C, class D>                                                                               
typename std::enable_if<                                                  
std::is_base_of<baseofA, A>::value &&                      
std::is_base_of<baseofB, B>::value &&      
std::is_base_of<baseofC, C>::value &&            
std::is_base_of<baseofD, D>::value>::type       
class library {
    //whatever
};
  • 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-05T10:25:43+00:00Added an answer on June 5, 2026 at 10:25 am

    You’re not using enable_if correctly. static_assert would be more appropriate in this case.

    template<class A, class B, class C, class D>       
    class library {
      static_assert(
        std::is_base_of<baseofA, A>::value &&                      
        std::is_base_of<baseofB, B>::value &&      
        std::is_base_of<baseofC, C>::value &&            
        std::is_base_of<baseofD, D>::value, 
        "template argument A must derive from baseofA and so on ..." );
          //whatever
    };
    

    If you want to use enable_if instead you must create a dummy template parameter that depends on the enabled type for it to work as you desire.

    template<class A, 
             class B, 
             class C, 
             class D, 
             class _ = 
               typename std::enable_if<                                                  
                 std::is_base_of<baseofA, A>::value &&                      
                 std::is_base_of<baseofB, B>::value &&      
                 std::is_base_of<baseofC, C>::value &&            
                 std::is_base_of<baseofD, D>::value>
               ::type>
    class library {
        //whatever
    };
    

    But IMO, the static_assert method is better because you can provide a descriptive error message instead of the compiler complaining about failing to find a type named type in the latter case.

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

Sidebar

Related Questions

In one of my projects, I have the following class template hierarchy : template
When I try to compile template class, I got the following errors: C.cpp: In
What is the function of the following C++ template class? I'm after line by
I have the following class: template <typename T> class matrix { private: int _n;
I really like the following template to create properties for class in VS2005 Type
I have the following template method declared in my interface: class IObjectFactory { public:
When compiling the following: template <class T> class Number { private: T num; public:
Given the following template: template <typename T> class wrapper : public T {}; What
I am trying to do the following: template <class T> std::ifstream& operator>> (std::ifstream& fin,
My base class, class Foo , is a template class which has the following

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.