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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:23:44+00:00 2026-05-13T12:23:44+00:00

I have some template code which compiles fine in VC9 (Microsoft Visual C++ 2008)

  • 0

I have some template code which compiles fine in VC9 (Microsoft Visual C++ 2008) but won’t compile in GCC 4.2 (on Mac). I’m wondering if there’s some syntactical magic that I’m missing.

Below I have a stripped-down example which demonstrates my error. Sorry if this example seems meaningless, I removed as much as I could to isolate this error.

In particular I have a template class S which has an inner class R which is also a template class. From a top-level template function foo, I am trying to call R::append which is a static member function of R:

template< typename C >
struct S {
    template< typename T >
    S<C> & append( const T & ) { return *this; }

    template< int B >
    struct R {
        template< typename N >
        static S<C> & append( S<C> & s, const N ) {
            return s.append( 42 );
        }
    };
};

template< typename C >
S<C> & foo( S<C> & s, const int n ) {
    S<C>::R<16>::append( s, n ); // error: '::append' has not been declared
    return s;
}

Anyone out there know what I’m doing wrong?

  • 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-13T12:23:44+00:00Added an answer on May 13, 2026 at 12:23 pm

    Having use both Visual Studio and gcc, it’s a known issue 🙂 And I used VS2003 and gcc 3.4.2 so it’s been like that for a while.

    If I remember correctly, the problem is due to the way templates are parsed on these compilers.

    gcc behaves as stated by the standard, and performs 2 parses:

    • the first when encountering the template, without any information on the types, at this point it necessitates some typename and template magic to help understand what’s going on
    • a second when actually instantiating the template with a given type

    on the other hand, VS only does one parse, at instantiation, and therefore can fully resolve the symbols without typename and template here and there.

    You have the same thing for methods:

    template <class Item>
    struct Test
    {
      template <class Predicate>
      void apply(Predicate pred);
    
      void doSomething { this->apply(MyPredicate()); }          // Visual Studio
      void doSomething { this->template apply(MyPredicate()); } // gcc
    }; // struct Test
    

    On the same topic, if you do something like:

    template <class Item>
    struct Test { static const std::string Name; };
    

    You need to actually define this static attribute for each instantiation of the template, or you’ll have an undefined symbol.

    VS accepts this syntax:

    const std::string Test<MyType>::Name = "MyType";
    

    But gcc asks for a little keyword:

    template <> const std::string Test<MyType>::Name = "MyType";
    

    You may think of VS as better since it asks less of you, but on the other hand gcc may warn you of mistakes in your template methods / classes as soon as it parses them the first time (ie without any actual instantiation) and personally, the sooner the better.

    Obviously, the good news is that if compiles on gcc (for these issues), it will also compile fine on Visual Studio.

    Since I am not a standardista though, I am not sure whether or not the standard actually demands or advises the 2-parses scheme.

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

Sidebar

Ask A Question

Stats

  • Questions 288k
  • Answers 288k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't have that tab either but I found a… May 13, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer The NSString you are creating from the number is not… May 13, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer I think I may have found an answer to my… May 13, 2026 at 5:24 pm

Related Questions

I am having some trouble hosting a WCF service inside a Windows Service. I
I'm looking at some codes which makes heavy uses of templates. It compiles fine
I've run into some annoying issues with const-correctness in some templated code, that ultimately
I have to make a decision regarding generalization vs polymorphism. Well the scenario is
I have a class, A , in C++/CLI which derives from a templated base

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.