Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) TemplateFunctionExample4

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppTemplateFunctionExample4/CppTemplateFunctionExample4.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

CONFIG(release, debug|release) {
  DEFINES += NDEBUG
}

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++

unix {
  QMAKE_CXXFLAGS += -Werror
}

win32 {
  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0
}

 

 

 

 

 

./CppTemplateFunctionExample4/main.cpp

 

#include <cstdlib>
#include <iostream>
#include <type_traits>

template <class T> void Cout(const T* t)
{
  std::cout << (*t) << '\n';
}

template <class T> void Cout(const T& t )
{
  std::cout << (t) << '\n';
}

int main()
{
  const int x = 42;
  const double * const p  = new double(123.456);

  std::cout << x << '\n';
  std::cout << p << '\n';

  Cout(x);
  Cout(p);
}

/* Screen output:

42
0x802808
42
123.456
Press <RETURN> to close this window...

*/

 

 

 

 

 

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