Created
July 26, 2013 17:40
-
-
Save jpmec/6090738 to your computer and use it in GitHub Desktop.
A simple example demonstrating how to print "Hello World" before the main() function is called.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Example showing how to print "Hello World" before main(). | |
* Expected output: | |
* Hello World | |
* Hello from main() | |
* | |
* Compile with: | |
* g++ -Wall test_cpp_print_before_main.cpp -o test_cpp_print_before_main | |
*/ | |
#include <iostream> | |
using namespace std; | |
/// A simple class that prints "Hello World" when constructed. | |
class HelloWorld | |
{ | |
public: | |
HelloWorld(void) | |
{ | |
cout << "Hello World" << endl; | |
} | |
}; | |
// Construct a const instance, | |
// will call constructor before main() is entered. | |
const HelloWorld hello_world = HelloWorld(); | |
int main(int argc, const char* argv[]) | |
{ | |
cout << "Hello from main()" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment