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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:10:25+00:00 2026-05-28T11:10:25+00:00

Here is the test code template <class T> void f() { T t; t.f<T>(0);

  • 0

Here is the test code

template <class T> void f()
{
  T t;
  t.f<T>(0); //compiles even without the "template" keyword, what am I missing?
}

class abc
{
  public:
  template <typename T>
  void f (int){}
};

int main()
{
  f<abc>();
}

I am using g++ 4.4.6. Thanks

P.S: I have edited my question considerably. Please don’t mind.

EDIT : I asked this question to EDG people and this is what Mike Herrick had to say

We do diagnose this as an error in –strict mode as well as any mode that enables dependent name lookup (e.g., –dep_name, –parse_templates). Dependent name lookup is disabled in GNU emulation modes, so we don’t emit this error in that case.

Dependent name processing requires that nonclass prototype instantiations
be enabled (see below). As with nonclass prototype instantiations, enabling
dependent name lookup is likely to cause compilation errors when compiling
code that was not written with the feature in mind.

The dependent name lookup rules require that nondependent names be
looked up at the point of use in the template definition, and that
overload resolution be performed on nondependent calls at that point.
For dependent calls, the set of names considered is the set visible
at the point of use in the template definition plus any names made
visible by argument-dependent lookup at the point of instantiation.
Note that built-in types have no associated namespaces, so calls
with only built-in types can only resolve to names visible in the
template definition. Furthermore, names from dependent base classes
are not visible to unqualified lookups.

The following illustrates some of the most common code problems encountered
when using dependent name lookup:

template <class T> struct B {
    void f();
  };

template <class T> struct A : public B<T> {
    X x;  // error: X not visible yet (formerly an error in strict mode)
    void g() {
      f();        // error: B<T>::f not visible
      this->f();  // must be written this way
      h(1);  // error: h(int) not visible using argument-dependent lookup
    }
  };
struct X {};
void h(int);
A<int> ai;
  • 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-28T11:10:26+00:00Added an answer on May 28, 2026 at 11:10 am

    The template keyword is required both because t is a dependent name and because f<T> is a dependent member function template specialization. The relevant specification is scattered throughout clause 14, but starts at §14.2/4 (in both C++03 and C++11).

    The problem is due to incorrect name lookup: gcc is finding the namespace-scope function template f at the point of declaration, then at the point of instantiation resolves f to the member function template of abc.

    If you rename either the namespace-scope function template or the member function template, you will get the correct behavior from the compiler.

    This is a longstanding gcc bug:

    Code with missing "template" keyword wrongly accepted

    Weird clash with same names in different scopes

    See also the many duplicate bugs resolved against both of those. I don’t see a Clang bug open for this.

    Name lookup from within a function template was underspecified in C++03; there were many defects reported on the subject and the specification has undergone major changes in C++11 to clarify details and corner cases and to fix subtle problems.

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

Sidebar

Related Questions

Here is a little test program: #include <iostream> class Test { public: static void
For example, my goal is to test the code given here: PHP script that
I am trying to test some of these code here http://ha.ckers.org/xss.html on my code.
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
I'm trying to understand how the following class template works (taken from here ),
I often hear around here from test driven development people that having a function
Here is a test description, testing the Create New Widget use-case. Confirm that you
here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
Here is a test framework to show what I am doing: create a new
Here is my test page (dont mind the layout right now) https://www.bcidaho.com/test_kalyani/employer-plans-test.asp i found

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.