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

  • Home
  • SEARCH
  • 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 8768401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:03:19+00:00 2026-06-13T17:03:19+00:00

The following case compiles fine in MS Visual Studio, but not in g++ 4.6.

  • 0

The following case compiles fine in MS Visual Studio, but not in g++ 4.6.

Compiling:

    template <typename T>
    struct get_type
    { typedef void type_;};

template <>
    struct get_type<float>
    { typedef float type_; };

template <>
    struct get_type<int>
    { typedef int type_; };

template <typename T, typename P=get_type<T>::type_> // <--- line 16
    struct get_destroy_type
    { static inline void exec(P a) {} };

Results in:

../testlibrary/testlibrary.h:16:34: error: expected type-specifier
../testlibrary/testlibrary.h:16:34: error: expected ‘>’

Doesn’t seem to like it when I use

get_type<T>::type_

as the template argument default. MS Visual Studio (Express 10) compiles this fine. What changes can I make to get g++ to compile this?

  • 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-13T17:03:20+00:00Added an answer on June 13, 2026 at 5:03 pm

    Use typename to disambiguate:

    template <typename T, typename P = typename get_type<T>::type_>
                                       |______|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet, which compiles fine, but when I try to run
My first code fragment compiles and works fine: template <class x> struct B1 {
The following code compiles fine with g++ (GCC) 4.7.1 20120721 , but fails with
Consider this code: template<typename T> class Base { template<typename U> friend void f(void *ptr)
I am using Visual Studio 2003 to compile and run following program. There are
When I try and compile the following code... #include <vector> template <class T> void
The following code compiles just fine, overwriting the values in v2 with those from
The following statement compiles fine and works as expected: val map : Map[_ >:
I have the following case: Edited: removed link In IE7 gives me different view
I have the following case: All boats have a boat type like shark ,

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.