J
John Goche
Hello,
I would like to know why the first three statements
produce output whereas the last one does not.
Also, should parentheses be included when
constructing such an instance on the heap?
What about on the stack? Why or why not.
Thanks,
JG
--- input code: ------------------------------------
#include <iostream>
class Foo {
public:
Foo() {
std::cout << "hello" << std::endl;
}
private:
int x;
};
int main() {
std::cout << "one" << std::endl;
Foo *foo = new Foo;
std::cout << "two" << std::endl;
Foo *bar = new Foo();
std::cout << "three" << std::endl;
Foo hello;
std::cout << "four" << std::endl;
Foo bye();
}
----- output: ------------------------------
$ ./hello
one
hello
two
hello
three
hello
four
-----------------------------------------------
I would like to know why the first three statements
produce output whereas the last one does not.
Also, should parentheses be included when
constructing such an instance on the heap?
What about on the stack? Why or why not.
Thanks,
JG
--- input code: ------------------------------------
#include <iostream>
class Foo {
public:
Foo() {
std::cout << "hello" << std::endl;
}
private:
int x;
};
int main() {
std::cout << "one" << std::endl;
Foo *foo = new Foo;
std::cout << "two" << std::endl;
Foo *bar = new Foo();
std::cout << "three" << std::endl;
Foo hello;
std::cout << "four" << std::endl;
Foo bye();
}
----- output: ------------------------------
$ ./hello
one
hello
two
hello
three
hello
four
-----------------------------------------------