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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:30:42+00:00 2026-05-16T10:30:42+00:00

Using GCC 4.2. I have this metatemplate for conditional type: template <bool condition, typename

  • 0

Using GCC 4.2.
I have this metatemplate for conditional type:

template <bool condition, typename Then, typename Else>
struct IF
{
    typedef Then RET;
};

template <class Then, class Else>
struct IF<false, Then, Else>
{
    typedef Else RET;
};

and when I use it like this:

template <typename T>
class Param
{
    IF< sizeof(int)<sizeof(long), long, int>::RET  i;
};

it works, but when I use it like this (trying to use template parameters):

template <typename T>
class Param
{
    IF< sizeof(int)<sizeof(long), T&, T* >::RET mParam;
};

I am getting this error code:

error: type 'IF<false, T&, T*>' is not derived from type 'Param<T>'

Why is it happening? How to solve it?
Thanks in advance!

  • 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-05-16T10:30:43+00:00Added an answer on May 16, 2026 at 10:30 am

    In the second case, what RET is, depends on the template type T. The compiler needs to be assured that it is going to be a type in all possible instantiations (and not perhaps a static member of some instantiation of IF). You do so with the typename keyword.

    template <typename T>
    class Param
    {
        typename IF< sizeof(int)<sizeof(long), T&, T* >::RET mParam;
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Compiling on linux using gcc. I would like to convert this to hex. 10
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
I am using gcc for windows . The OS is windows XP . How
I'm using GCC to generate a dependency file, but my build rules put the
I'm using GCC; __FILE__ returns the current source file's entire path and name: /path/to/file.cpp
I'm temporarily using gcc 2.95.2, and instead of having a sstream header, it defines
I'm fine working on Linux using gcc as my C compiler but would like
I'm getting the invalid lvalue error using gcc 3.4.6. The line that invokes the
I'm accessing an Ubuntu machine using PuTTY, and using gcc. The default LANG environment
I'm getting a totally bizzare error trying to compile a C program using GCC.

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.