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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:57:13+00:00 2026-05-15T18:57:13+00:00

I found a strange issue when porting my code from Visual Studio to gcc.

  • 0

I found a strange issue when porting my code from Visual Studio to gcc. The following code compiles fine in Visual Studio, but results in an error in gcc.

namespace Baz
{
   template <class T>
   class Foo
   {
   public:
      void Bar()
      {
         Baz::Print();
      }
   }; 

   void Print() { std::cout << "Hello, world!" << std::endl; }
}

int main()
{
   Baz::Foo<int> foo;
   foo.Bar();

   return 0;
}

My understanding is that this should compile OK, as the class shouldn’t be compiled until the template is instantiated (which is after Print() is defined). However, gcc reports the following:

t.cpp: In member function ‘void Baz::Foo::Bar()’:
Line 8: error: ‘Print’ is not a member of ‘Baz’

Who’s right? And if gcc is right, why?

  • 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-15T18:57:14+00:00Added an answer on May 15, 2026 at 6:57 pm

    gcc is right. It is because Baz is a namespace and namespaces are parsed top to bottom, so the declaration of Baz::Print is not visible from inside Foo (since it is beneath it).

    When the template is instantiated, only names visible from the template definition are considered, not counting Koenig lookup (which wouldn’t change anything in your case).

    If Baz were a struct or class, your code would work, since these are parsed in two phases (first declarations, then bodies), so anything declared in a struct or class is visible inside eg. member functions, regardles of their order in the source file.

    You can make it work by declaring Baz::Print before Foo.

    Quoting the standard:

    14.6.3 Non-dependent names

    Non-dependent names used in a template definition are found using the usual name lookup and bound at the
    point they are used.

    14.6.4 Dependent name resolution

    In resolving dependent names, names from the following sources are considered:

    • Declarations that are visible at the point of definition of the template.
    • Declarations from namespaces associated with the types of the function arguments both
      from the instantiation context (14.6.4.1) and from the definition context.

    (end quotation)

    When Print is nondependent (as it is now), it wouldn’t be found since it is looked up before its declaration (in the template definition context). If it were dependent, it wouldn’t be the first case (same as when nondependent), and Baz is not associated with int (the template parameter) in any way, so it wouldn’t be searched according to the second case either.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • 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 protected void layout(int width, int height) { setExtent(Math.min(width, getPreferredWidth()), Math.min(height,… May 16, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer Have you tried NOT setting the cookie.Expires or at least… May 16, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer C++ - if you know what you're doing. You will… May 16, 2026 at 4:33 pm

Trending Tags

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

Top Members

Related Questions

Debugging some finance-related SQL code found a strange issue with numeric(24,8) mathematics precision. Running
I've found a strange issue with subclassing and dictionary updates in new-style classes: Python
I've found a strange issue when using unset function in combination with a SimpleXML
I've just found a strange issue with my sub classed mkannotationview. When I add
I am having a strange issue that I can't seem to resolve. Here is
I'm having a strange issue with cookie visibility between an authentication servlet and our
I have a strange issue with JUnit 4 tests in Eclipse 3.5 that I
I'm struggling with a strange issue. According to http://github.com/sinatra/sinatra (secion Filters) a response object
I have a strange issue! I am trying to remove an event listener on
I have an iPhone app and one of my users found a really strange

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.