Created
June 30, 2011 19:52
-
-
Save threez/1057058 to your computer and use it in GitHub Desktop.
A simple example to show cpp to my friends ;-)
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
#include <iostream> | |
template <typename MsgType> | |
class Greeting { | |
private: | |
MsgType m_pre; | |
MsgType m_post; | |
public: | |
Greeting(MsgType pre) | |
: m_pre(pre) {} | |
Greeting(MsgType pre, MsgType post) | |
: m_pre(pre), m_post(post) {} | |
void hello(MsgType name) { | |
std::cout << m_pre << name; | |
if(m_post != NULL) std::cout << m_post; | |
std::cout << std::endl; | |
} | |
}; | |
int main(int argc, char* argv[]) { | |
Greeting<const char*> foo("Hallo "); | |
foo.hello("Ruben"); | |
Greeting<const char*> bar("Hey", ", was geht ab?"); | |
bar.hello("Vincent"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment