Does this code compile? If yes, what does it do? If not, why not?
class MyObject {
public:
void doSomething() {}
};
int main() {
MyObject o();
o.doSomething();
}Show answer and explanation
It does not compile at the member call. MyObject o(); declares a function named o returning MyObject; it does not construct an object. Use MyObject o; or MyObject o{};.
It does not compile at the member call. MyObject o(); declares a function named o returning MyObject; it does not construct an object. Use MyObject o; or MyObject o{};.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.