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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:06:46+00:00 2026-05-28T15:06:46+00:00

void foo(int) { } class X { void foo() { } void bar() {

  • 0
void foo(int)
{
}

class X
{
    void foo()
    {
    }

    void bar()
    {
        foo(42);
        // error: no matching function for call to 'X::foo(int)'
        // note: candidate is:
        // note: void X::foo()
        // note:   candidate expects 0 arguments, 1 provided        
    }
};

Why is C++ unable to call the free function (which is the only one with the correct signature)?

  • 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-28T15:06:47+00:00Added an answer on May 28, 2026 at 3:06 pm

    The logical reason is Consistency.

    • Suppose as per the suggestion, compiler resolves foo(42) to
      ::foo(int).
    • Now after sometime, if you change X::foo() to X::foo(int) then
      foo(42) will be resolved to X::foo(int). Which is not consistent.

    That is the also the reason why derived class function hides base class function when there are similar names.

    Such cases can be resolved in 2 ways;

    (1) Give fully qualified name (e.g. ::foo(42))

    (2) Use using utility; e.g.

    void bar()
    {
      using ::foo;
      foo(42);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Foo { public: void bar(); }; void Foo::bar() { static int n =
Specifically, is the following legal C++? class A{}; void foo(A*); void bar(const A&); int
What is actually passed in call by reference to a function? void foo(int &a,int
class foo { public void bar(int i) { ... }; public void bar(long i)
public class Foo { public void DoFoo() { int x; var coll = TheFunc(bar,
#include <initializer_list> #include <utility> void foo(std::initializer_list<std::pair<int,int>>) {} template <class T> void bar(T) {} int
For the C++ code fragment below: class Foo { int a[]; // no error
How do I call start() below? package com.example.test; class Bar {} public class Foo<K>
Code #include <OOLua/oolua.h> class foo { public: int bar(); }; OOLUA_CLASS_NO_BASES(foo)//class has no bases
I've got following code: File: Foo.h class Foo { friend void Bar(); }; File:

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.