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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:31:41+00:00 2026-05-27T15:31:41+00:00

In c++ we can calls method of a class without instantiating it. Such as;

  • 0

In c++ we can calls method of a class without instantiating it. Such as;

MyClass mc;
mc.method();

what are the advantages & disadvantages of using methods of class without instantiating it? When should we use this type?

  • 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-27T15:31:42+00:00Added an answer on May 27, 2026 at 3:31 pm

    Just because you haven’t explicitly invoked a constructor, doesn’t mean you haven’t instantiated it. The form you’ve used invokes the default constructor. This may or may not setup the class correctly, but that’s a matter for the class’s author to sort out, not the code that uses it.

    EDIT: It occurs to me that the advice I gave might confuse more than it helps, so I’ll provide a couple of examples:

    The following class has a trivial default constructor that doesn’t initialise its members:

    class Point {
        int x, y;
        Point() { }
        Point(int x, int y) : x(x), y(y) { }
    };
    

    You can use this class with or without an explicit constructor:

    Point p;
    Point r(2, 3);
    

    In both forms above, the class is instantiated and the instance is ready for use without causing any crashes or invoking undefined behaviour. In the case of p, however, the member variables x and y haven’t been initialised, and will thus have values that are, for all intents and purposes, random. Typically, you would populate such an object by setting its member variables explicitly…

    Point a;
    a.x = f();
    a.y = g();
    

    …or passing the object to another function to populate…

    void f(Point& p) { p = something(); }
    ⋮
    Point b;
    h(b);
    

    In other cases, the default constructor must initialise the object in a non-trivial way:

    template <typename T>
    class MyArray {
    public:
        MyArray() : len_(0), capacity_(0), arr_(0) { }
        void add(const T& t) {
            if (len_ == capacity_) grow();
            arr_[len_++] = t;
        }
        ⋮
    private:
        size_t len_, capacity_;
        T* arr_;
    
        void grow() { … }
    };
    

    The purpose of the constructor is to convert raw memory into a usable object. In the case of Point, no action is required for an instance to be usable. In the case of MyArray, len_ and capacity_ must be set to zero at construction time so that member functions like add() behave correctly (I also set arr_ to the null pointer for good measure).

    The key message in all of this is that the object may or may not be initialised, but it is instantiated.

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

Sidebar

Related Questions

Using Groovy's package name convention, I can intercept Groovy method calls to a Java
I am using cglib to enhance a HashMap so I can intercept method calls
How to create a generic method which can call overloaded methods? I tried but
I have a utility class with some static methods which I use in some
I have a class called CategoryViewController and its viewDidLoad method calls this method: -
The RFC for a Java class is set of all methods that can be
Does anyone knows how can I invoke method dynamically without reflection? I`ll try to
Opah! Is there any way I can call a method in the controller through
Can I call public method from within private one: var myObject = function() {
How can I call a method asynchronously ?

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.