c++ - Creating an instance of a class with () -


i have question : constructor used when create instance of class classname instance() in c++ ?

example:

#include <iostream>  using namespace std;  class test { private:     test()     {         cout << "aaa" << endl;     }  public:     test(string str)     {         cout << "string = " << str << endl;     } };  int main() {     test instance_1(); // instance_1 created... using constructor ?     test instance_2("hello !"); // ok      return 0; } 

thanks !

tricky! expect compilation fail default constructor private. however, compiles , nothing created. reason?

test instance_1(); 

... function declaration! (which returns test , takes nothing.)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -