What does the following code do?
Is a Foo object created and then immediately destroyed? I've seen this used in a few examples and I don't understand what the purpose of Foo() is here.Code:class Foo {}; int main() { Foo(); }
What does the following code do?
Is a Foo object created and then immediately destroyed? I've seen this used in a few examples and I don't understand what the purpose of Foo() is here.Code:class Foo {}; int main() { Foo(); }
When you declare a function Foo(); inside the class Foo, it will be a constructor...
in that case it does nothing... but for instance, if you had a class like this
when you declared an object with a and b it would call the constructor...Code:Class Foo{ public: int x, int y; Foo(int a, int b){ x = a; y = b; } };
and then FooObj.x would be 1 and FooObj.y would be 2... something like this :P...Code:Foo FooObj(1, 2);
Last edited by Hirosh; 09-18-2009 at 06:10 AM.
I was more referring to the fact that main calls a constructor without binding the created object to a variable.
What's wrong with the example above? It compiles without warnings, and I have no idea what it does.
In particular, if Foo is a class, what does this do when used outside the class body:
Code:Foo();