Advertisement
Stiepen

OOP Hello World

Mar 19th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. // File prog.cpp - main entry point:
  2.  
  3. int main() {
  4.     HelloWorld helloWorld;
  5.     helloWorld.sayHello();
  6.     return 0;
  7. }
  8.  
  9. // File helloworld.h - class header File
  10. #ifndef HELLOWORLD_H // Prvent this file from being loaded twice
  11. #define HELLOWORLD_H
  12.  
  13. class HelloWorld {
  14. public:
  15.     HelloWorld();                   // Default constructor
  16.     HelloWorld(const HelloWorld&);  // copy constructer
  17.     ~HelloWorld();                  // Destructor
  18.     void sayHello();                // Some instant method
  19. };
  20. #endif
  21.  
  22. // File helloworld.cpp - class code File
  23. #include <iostream>
  24.  
  25. HelloWorld::HelloWorld() {} // nothing to init in this case
  26. HelloWorld::HelloWorld(const HelloWorld&) {} // no stuff here either
  27. HelloWorld::~HelloWorld() {} // no code to be executed on destruct
  28. void HelloWorld::sayHello() {
  29.     std::cout << "Hello World" << std::endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement