Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TemplateClassExample3

 

STLQt CreatorWindows

 

Template class example 3: class that has an integer template type is a template class example.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppTemplateClassExample3/CppTemplateClassExample3.pro

 

include(../../ConsoleApplication.pri)
SOURCES += main.cpp

 

 

 

 

 

./CppTemplateClassExample3/main.cpp

 

#include <iostream>

template <int I>
struct Person
{
  ///Every Person<I> can say hello
  void SayHello() const;
};


//Person<0> says hello in a happy way
template <>
void Person<0>::SayHello() const { std::cout << "Hello!\n"; }

//Person<1> says hello in a grumpy way
template <>
void Person<1>::SayHello() const { std::cout << "Moi\n"; }

int main()
{
  const Person<0> p;
  p.SayHello();
  const Person<1> q;
  q.SayHello();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml