(C++) TemplateFunctionExample4
February 24, 2017 · View on GitHub
(C++) TemplateFunctionExample4
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
STL: GNU ISO C++ Library, version
4.9.2
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... */