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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:27:45+00:00 2026-05-25T23:27:45+00:00

Over the weekend, I had specific problem with function overload resolution that I can’t

  • 0

Over the weekend, I had specific problem with function overload resolution that I can’t seem to solve.
The code below is a distillation of the problem:

#include <iostream>
using namespace std;

template<typename T>
void f(const T& t)
{
    cout << "In template function." << endl;
}

class C
{
public:
    void f() { cout << "In class function." << endl; }
    void g() { int i=0; f(i); }
    void h() { int i=0; f<int>(i); }
    void i() { extern void f(int); int i=0; f(i); }
};

int main()
{
    cout << "Test" << endl;
    C c;
    c.i();
    return 0;
}

1) C::g won’t compile because the compiler won’t try the template. It just complains that there is no C::f to match.

2) C::h won’t compile for no reason that is obvious to me. The message is “expected primary-expression before ‘int'”

3) C::i will compile, but (after commenting out g and h) it won’t link to anything. I think I understand this: the extern is forcing the linker to look into another compilation unit, but any template definition would be in this compilation unit.

I would appreciate any clarification on the reasons for 1 and 2. Also, ultimately, can someone suggest a way to get this to work that doesn’t involve creating another compilation unit?

  • 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-25T23:27:46+00:00Added an answer on May 25, 2026 at 11:27 pm

    Look here: http://ideone.com/zs9Ar

    Output:

    Test
    In template function.

    #include <iostream>
    using namespace std;
    
    template<typename T>
    void f(const T& t)
    {
        cout << "In template function." << endl;
    }
    
    class C
    {
    public:
        void f() { cout << "In class function." << endl; }
        void g() { using ::f; int i=0; f(i); }
    };
    
    int main()
    {
        cout << "Test" << endl;
        C c;
        c.g();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading about ASP.net MVP pattern over this weekend and it seem like even
What is a great problem I can give a couple of potential devs that
Over the weekend I realized that an application I'm working on which uses NHibernate
It seems that over the weekend, the following Delegate method - (void)OAuthTwitterController:(SA_OAuthTwitterController *)controller authenticatedWithUsername:(NSString
This was bugging me over the weekend: What is a good way to solve
Over the weekend, another programmer added a file to a project and committed it
Over the weekend, for some reason, one of our servers has decided to start
Our networks guys installed this patch over the weekend to our single server sharepoint
I ran into a strange issue over the weekend while I was working on
I've been messing around with Python over the weekend and find myself pretty much

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.