1

Sorry I was unable to find any keyword to search for this problem. My code is below

#include <iostream>
using namespace std;
class Name {
    public:
        Name() {
            cout << "Asif";
        }
};

int main() {
    Name obj(); // why Constructor not calling here?

    return 0;
}

If it's not calling the constructor then what process is running in this code?

Anindya Dutta
  • 1,972
  • 2
  • 18
  • 33
Asif Mushtaq
  • 3,658
  • 4
  • 44
  • 80

1 Answers1

3
 Name obj(); // why Constructor not calling here? 

This is a function declaration, returning a Name object

Just do

Name obj;
ivanw
  • 491
  • 8
  • 16