I am new to C ++ and noticed that the following lines of code act differently
MyClass c1;
c1.do_work()
MyClass c2();
c2.do_work()
MyClass c3{};
c3.do_work()
with the header file as
class MyClass {
public:
MyClass();
void do_work();
};
Can you explain to me what is the difference between the three ways to create an object? And why does the second method create a compiler error?
source
share