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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:49:05+00:00 2026-05-24T23:49:05+00:00

The question is in reference to this , which was posted a little while

  • 0

The question is in reference to this, which was posted a little while earlier.
While the OP was happy accepting the answer which solved his problem I was a little intrigued with a detail as to why compiler gave a seemingly wrong error.

Below is a small code sample I created to demonstrate the same:

    class YourClass
    {
    };

    class YourClass2
    {
    };
    class MyClass
    {
        public:
            void doSomething(YourClass2 obj)
            {
                //Nothing more Interesting to do
            }

    };

    int main()
    {
        YourClass *ptr = new YourClass();
        MyClass obj;
        obj.doSomething(ptr);

        return 0;
    }

Compiling this with GCC(4.3.4) gives a seemingly strange error result:

prog.cpp: In function ‘int main()’:
prog.cpp:23: error: no matching function for call to ‘MyClass::doSomething(YourClass*&)’
prog.cpp:13: note: candidates are: void MyClass::doSomething(YourClass2)

So the Question is:
Why does the compiler treat the call,

obj.doSomething(ptr);

as call to a function with prototype,

MyClass::doSomething(YourClass*&)

and not

MyClass::doSomething(YourClass*)

which seems to be the obvious case.

  • 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-24T23:49:05+00:00Added an answer on May 24, 2026 at 11:49 pm

    As others have stated, the compiler is trying to be helpful, and probably confusing you. Lets start with the simplest error:

    error: no matching function for call to obj.doSomething(ptr)

    While the error message is correct, the information that it provides is very limited. In this example the code is simple to follow, but consider a more complex piece of code. You read the error message and you may think… what’s obj?, what’s ptr? So it tries to help you and tells you what obj is:

    error: no matching function for call to ‘MyClass::doSomething(ptr)’

    Well, that’s better, it is telling you at least in what class you need to look for the overload, but consider that the class was std::ostream and the function operator<<… there are just too many overloads, and still, what is the type of ptr? So it moves forward and tries to describe the argument: The argument is an lvalue of type YourClass*… and I have seen that type of error message produced in the past:

    error: no matching function for call to ‘MyClass::doSomething’ that takes an YourClass* lvalue as argument.

    Ok, so the error report is complete. Now think that the function might have more arguments, and the error message can turn into a complex beast (imagine a list of 5 “rvalue of type XXX and an lvalue of type YYY and …”). The next thing is making the syntax of the error message just as precise (the lvalue-ness of the argument is important, or the rvalue-ness would be important, so that piece of information has to be present). So it rewrites the error message again:

    error: no matching function for call to ‘MyClass::doSomething(YourClass*&)’

    The problem is that you are trying to interpret that as a function signature, but it is rather the description of the function call.

    Error messages are not defined in the standard, and they differ from one compiler to another, even from one version to another within the same compiler. At the end of the day you need to learn to read the error messages and what they mean.

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

Sidebar

Related Questions

This is the super simple version of the question I posted earlier (Which I
I'm writing this question with reference to this one which I wrote yesterday. After
In reference to this answer to a Stack Overflow question : what is bench-testing
This is in reference to a question I asked earlier. Aside from viewing the
This is in reference to the question previously asked The problem here is, each
I saw this in an answer to another question , in reference to shortcomings
In reference to this question: Which is prefered CTabCtrl vs CPropertySheet I have a
With reference to this question , I would like to know which version (.net
With reference to this question , I would like to know which version (.net
I hope I get an answer to my question this time, I already posted

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.