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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:38:27+00:00 2026-06-01T07:38:27+00:00

I have a class with defined functions that need to be passed as parameters.

  • 0

I have a class with defined functions that need to be passed as parameters.
I want to setup a new instance of this class (with parameters) as an object(?).

Getting stuck with the syntax.

class classname{
void classfunction1(int, int);
void classfunction2(int, int);
};

void classname::classfunction1 (int a, int b)
{ // function }

void classname::classfunction2 (int a, int b)
{ // function uses classfunction1 }

I want to define the params for classfunction1, which will be used in classfunction 2 and assign an object(?), of that type so that intellisense will pick it up.

Pseudo:

int main(){
classname(20, 20) object;
object.classfunction2(50, 50);
}

Thanks!

  • 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-01T07:38:28+00:00Added an answer on June 1, 2026 at 7:38 am

    Your main is a bit wonky at the minute.

    int main(){
        classname(20, 20) object; // You are incorrectly calling a constructor which does not exist
        object.classfunction2(50, 50); // more like correct behavior.
    }
    

    The class you have defined does not have any member variables, so it does not store any data. It only holds two functions. So this means that you can use the “default constructor” that the compiler defines for every class ( you can provide your own if you wish ).

    int main(){
        classname object; // Call the default constructor
        object.classfunction1(10, 20); // Call the functions you want.
        object.classfunction2(50, 50); 
    }
    

    If you wanted to provide a constructor you should do something like:

    class classname{
      public:
        classname(int variable1, int variable2): 
                member1(variable1), member2(variable2){}; //note that there is no return type
        void classfunction1(); //because instead of taking parameters it uses member1 & 2
        void classfunction2(int, int);
    
      private: 
        int member1;
        int member2;
    };
    

    You main would then look like:

    int main(){
        classname object(10, 20); // Call the default constructor. Note that the (10, 20) is AFTER "object".
        object.classfunction1();  // Call the function... it will use 10 and 20.
        object.classfunction2(50, 50); //This function will use 50, 50 and then call classfunction1 which will use 10 and 20.
    }
    

    A couple of things to note: The way you attempted to call the first constructor was wrong, you need the parameters after the variable name.
    See comments below for another thing to watch out for.

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

Sidebar

Related Questions

I have a user defined class that I want to create a public List
I have a functional AdjacencyListGraph class that adheres to a defined interface GraphStructure. In
I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have a class defined like this, with the appropriate getter and setter methods...
We have a class Car defined like this in a car.rb file class Car
I have a class Message that has a std::string as a data member, defined
I have a dll that was written in c++, I need to use this
We have some code that looks like this: class Serializer { public: template<class Type>
I have the following function defined inside my linked list class. The declaration in

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.