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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:32:52+00:00 2026-06-09T12:32:52+00:00

EDIT: thanks for all the speedy responses, I have a much better understanding of

  • 0

EDIT: thanks for all the speedy responses, I have a much better understanding of this concept now. Also, I’ll try to make my error messages more clear next time.
EDIT: updated with my newest code. the error happens on line 18. Also, I’m beginning to wonder if my latest issue has to do with the original class itself?

I’m trying to teach myself classes and objects in C++. I did it once by just declaring a void function, outputting something on the screen, calling the object in main and everything worked fine.

Now, I wanted to expand upon this and make a simple addition thing. However, I get a couple errors on Code Blocks:

error: invalid use of non-static member function 'int Addition::add(int, int)'
error: no matching function for call to 'Addition::add()'

Here’s my code:

#include <iostream>

using namespace std;

class Addition {
public:
int add (int x, int y) {
int sum;
sum=x+y;
return sum;
}
};

int main()
{
int num1;
int num2;
int ans=addobj.add(num1,num2);
Addition addobj;
addobj.add(num1,num2);
cout<<"Enter the first number you want to add"<<endl;
cin>>num1;
cout<<"Enter the second number you want to add"<<endl;
cin>>num2;
cout<<"The sum is "<<ans<<endl;
}
  • 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-09T12:32:53+00:00Added an answer on June 9, 2026 at 12:32 pm

    One of the most important things, a developer should learn to do is to read compiler’s messages. It’s clear enough:

    error: no matching function for call to 'Addition::add()'
    

    Your function in your class is

    int add (int x, int y)
    

    it takes 2 arguments and you pass none:

    addobj.add();
    

    You have 2 options:

    • create and initialize x and y inside your main and pass them as arguments
    • make add without parameters, create x and y inside add‘s body, as their values are taken from user input.

    In this case, as the function’s name is add, I’d chose the first option:

    • declare int x, y; inside your main
    • read the user input inside the main (the part, where you use cin and cout)
    • pass the x and y as arguments to add like this: addobj.add( x, y );
    • store the result (if needed), like this: int result = addobj.add( x, y );
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have fixed all but two warnings now, so thank you all for
Please let me know if you have any idea about it. Thanks EDIT What
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
EDIT Solution this was the solution, thanks to @mprivat: from mysql_wrapper2 import Mysql import
Edit: My problem is fixed thanks to @Grumpy - still, if you have general
My sites are pretty much all AJAX now, and I'm pushing jQuery animations to
EDIT - Thanks all - I knew it would be simple...couldn't see the wood
Why new()/delete() is slower than malloc()/free()? EDIT: Thanks for the answers so far. Please
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
EDIT: I figured it out from Bergi's answer in the end. Thanks Bergi. pubPrivExample

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.