c++ - C++11 Difference in Constructors (Braces) -
c++ - C++11 Difference in Constructors (Braces) -
i quite new c++ , have observed, next lines of code deed differently
myclass c1; c1.do_work() //works myclass c2(); c2.do_work() //compiler error c2228: left side not class, structure, or union. myclass c3{}; c3.do_work() //works
with header file
class myclass { public: myclass(); void do_work(); };
can explain me, difference between 3 ways of creating object is? , why sec way produce compiler error?
ways 1 , 3 phone call default constructor.
myclass c3{};
is new initialization syntax called uniform initialization. called default brace initialization. however:
myclass c2();
declares function c2
takes no parameters homecoming type of myclass
.
c++ c++11 constructor most-vexing-parse
Comments
Post a Comment