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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:34:29+00:00 2026-05-26T23:34:29+00:00

I stumbled on the same problem of nested templates described here . The following

  • 0

I stumbled on the same problem of nested templates described here.

The following code :

# include <cstdlib>  // for std::size_t

template<std::size_t N>
class Outer
{
public :
  template<typename T>
  class Inner
  {
      public :
        inline Inner<T> & operator ++ (void) ;
        inline Inner<T>   operator ++ (int) ;
  } ;
} ;

template<std::size_t N>
template<typename T>
inline typename Outer<N>::template Inner<T> & Outer<N>::Inner<T>::operator ++ (void)
{   //                    ^^^^^^^^ Point Of Interest : MSVC is the only one who complains
    // preincrement
}

template<std::size_t N>
template<typename T>
inline typename Outer<N>::template Inner<T>   Outer<N>::Inner<T>::operator ++ (int)
{   //                    ^^^^^^^^ Point Of Interest
    // postincrement
}

compiles fine with MinGW 4.5 (i.e. gcc) as long as the template keyword is present in the return type, but this makes MSVC2010 complain about declaration/definition mismatch :

error C2244: 'Outer::Inner::operator ++' : unable to match function definition to an existing declaration
1>  definition
1>    'Outer::Inner &Outer::Inner::operator ++(void)'
1>  existing declarations
1>    'Outer::Inner Outer::Inner::operator ++(int)'
1>    'Outer::Inner &Outer::Inner::operator ++(void)' <- This is what it wants !

When removing the template keyword, MSVC compiles fine while gcc becomes angry :

error: non-template 'Inner' used as template
note: use 'Outer::template Inner' to indicate that it is a template

Accoding to the post linked above, MSVC seems to be the faulty. So my questions :

  • How to adapt the above code in order to compile with both MSVC and GCC ?
    I really want to avoid this awful preprocessor hack :

    # ifdef MSVC
    # define nested_template 
    # else
    # define nested_template template
    # endif
    

And then use nested_template to please MSVC where it doesn’t like template.

  • If impossible, how to refactor/redesign the code to avoid the nested templates case ?
  • 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-26T23:34:30+00:00Added an answer on May 26, 2026 at 11:34 pm

    Actually, the define is the way to go for cross compiler support in so many places where you need the nested template. Boost does it too!

    The alternative is to seperate all your nested templates in extra headers and have different include pathes in MSVC and GCC.

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

Sidebar

Related Questions

I have stumbled upon a problem when calling a nested Async which happens to
In our project we've stumbled upon the following problem: we need to provide our
I stumbled across this code and am too proud to go and ask the
I stumbled across this problem in F#. Suppose, I want to declare two types
I stumbled upon this code and I am curious as to what use may
I stumbled across this C code today. Can anyone tell me what the 'where'
I've stumbled accross this code in production and I think It may be causing
I'm hoping someone happens to have stumbled upon the following issue before. My Java
While playing around with one-to-one associations in castle activerecord I stumbled upon the following
I'm stuck with a problem considering my Display class, which extends Canvas. A single

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.