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

The Archive Base Latest Questions

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

The following code is not accepted by GCC 4.6: void F(int x,char y) {

  • 0

The following code is not accepted by GCC 4.6:

void F(int x,char y)
{
}
template<typename T>
void G(T t)
{
    F(t);
}
void F(int x)
{
}

int main()
{
    G(5);
    return 0;
}

Should it be?

If not, does anyone have a good idea for a work-around? The real world scenario where this occurs is where G is part of a library for solving a particular kind of problem, needing a user-supplied helper function called F. However, for different kinds of problems, F takes different number of parameters. A few sample implementations of F are shipped with the library.

What is happening is that depending on the #include-order used by the client, only the “wrong kind” of F may be visible at template declaration time, and GCC then gives up, without waiting until the user-provided, correct, F is defined. This is even though template instantiation happens after the correct F is defined.

Update: Yes I know it works if all declarations of F happen before G, or if all declarations of F happen after G. However, that doesn’t really help me very much.

Update: In the code this minimal example is adapted from, F is really called ‘read’. And the first declaration of read has nothing at all to do with the second. The first declaration is in one header file, and the second in another. I don’t want to introduce ‘strange’ rules regarding include-file order, especially when the versions of ‘read’ have nothing to do with one another.

  • 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-13T19:15:04+00:00Added an answer on June 13, 2026 at 7:15 pm

    At instantiation, only argument dependent lookup is done. You can fix your case by using an argument whose type resides in the namespace of your F

    void F(int x,char y)
    {
    }
    template<typename T>
    void G(T t)
    {
        F(t);
    }
    void F(int x)
    {
    }
    
    template<typename T>
    struct wrapper {
     operator T() const { return t; }
     T t;
    };
    
    template<typename T> wrapper<T> make_wrapper(T t) {
      wrapper<T> w = { t };
      return w;
    }
    
    int main()
    {
        G(make_wrapper(5));
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
Why does the following code not allow foo(ptr) to be called ? #include <boost/scoped_ptr.hpp>
The following code is not working: private void fileNameLinkButton_Click(object sender, RoutedEventArgs e) { HyperlinkButton
The following code does not time out in Ruby 1.9.3p194 (2012-04-20) [i386-mingw32]: require 'timeout'
The following code does not want to compile. See the included error message. Code:
Consider the following code: struct A { A& add( int i ) { return
Following code transfer file successfully, but does not print in lable that it has
The following line of code <% invite.accepted ? { @going, @not_going = 'selected', ''
Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
The following class is not thread-safe (as proven in Proving the following code not

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.