(C++) TemplateClassExample5
March 5, 2018 · View on GitHub



Template class example 5: copy policy of integer class is a template class example.
- Download the Qt Creator project 'CppTemplateClassExample5' (zip)
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: ./CppTemplateClassExample5/CppTemplateClassExample5.pro
include(../../ConsoleApplication.pri) include(../../Libraries/Boost.pri) SOURCES += main.cpp
./CppTemplateClassExample5/main.cpp
enum class IntCopyPolicy { allow, forbid }; template <IntCopyPolicy copy_policy> struct Int; template <> struct Int<IntCopyPolicy::forbid> { Int(const int x) : m_x(x) {} Int<IntCopyPolicy::forbid>(const Int<IntCopyPolicy::forbid>&) = delete; Int<IntCopyPolicy::forbid>& operator=(const Int<IntCopyPolicy::forbid>&) = delete; private: int m_x; }; template <> struct Int<IntCopyPolicy::allow> { Int(const int x) : m_x(x) {} private: int m_x; }; int main() { const Int<IntCopyPolicy::allow> a(123); const Int<IntCopyPolicy::forbid> b(123); const Int<IntCopyPolicy::allow> c(a); //const Int<IntCopyPolicy::forbid> d(b); //Won't compile }