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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:52:13+00:00 2026-06-03T05:52:13+00:00

Is it possible to invoke a c++ class method without first creating a class

  • 0

Is it possible to invoke a c++ class method without first creating a class instance?

Suppose we have the following code:

// just an example 
#include <iostream>
using namespace std;

class MyClass {
    public:
        MyClass();
        ~MyClass();
        int MyMethod(int *a, int *b);
};

// just a dummy method
int MyClass::MyMethod(int *a, int *b){;
    return a[0] - b[0];
}

Here’s another example:

#include <iostream>
using namespace std;

class MyClassAnother {
    public:
        MyClassAnother();
        ~MyClassAnother();
        int MyMethod(int *a, int *b);
};

// just a dummy method
int MyClassAnother::MyMethod(int *a, int *b){;
    return a[0] + b[0];
}

As we can see, in the above examples, both classes have no internal variables and use dummy constructors / destructors; Their sole purpose is to expose one public method, MyMethod(..). Here’s my question: assume there are 100 such classes in the file (all with different class names, but with an identical structure — one public method having the same prototype — MyMethod(..).

Is there a way to invoke the MyMethod(..) method calls of each one of the classes without first creating a class instance for each?

  • 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-03T05:52:14+00:00Added an answer on June 3, 2026 at 5:52 am

    Use the keyword ‘static’ to declare the method:

    static int MyMethod( int * a, int * b );
    

    Then you can call the method without an instance like so:

    int one = 1;
    int two = 2;
    
    MyClass::MyMethod( &two, &one );
    

    ‘static’ methods are functions which only use the class as a namespace, and do not require an instance.

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

Sidebar

Related Questions

Is it possible in Delphi to have a class method invoke an inherited instance
is it possible to invoke a delegate method of a class by code? In
Is it possible to invoke method A.F() from instance of B class except of
I'm using the following method to invoke a class inside a jar file: invokeClass(path.to.classfile,
Suppose I have Objective C interface SomeClass which has a class method called someMethod
Say I have class B derived from class A Is it possible to invoke
Possible Duplicate: Copy Constructor is not invoked # include <iostream> using namespace std; class
Just curious here: is it possible to invoke a Windows Blue Screen of Death
I have a static method defined in a base class, I want to override
First, a little introduction. I have to functions: static class C { static void

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.