Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MSVCStatic
#include <iostream> // 1 static int initBeforeMain = [] { std::cout << "1 initBeforeMain" << std::endl; return 10; }(); // 2 struct Base { static int initInBase; }; int Base::initInBase = [] { std::cout << "2 initInBase" << std::endl; return 10; }(); struct Derived : Base {}; // 3 template<typename T, T> struct StaticInitializer { }; template<class T> struct BaseT { static int initInBase; using initStatic = StaticInitializer<int&, initInBase>; }; template<class T> int BaseT<T>::initInBase = [] { std::cout << "3 initInBase template" << std::endl; return 10; }(); struct DerivedT : BaseT<int> {}; // 4 template<typename T, T> struct BitFieldSize { constexpr static int value = 0; }; using CharT = char; template<typename T> struct BaseWithoutNewTypes { static int initInBase; CharT :BitFieldSize<int&, initInBase>::value; }; template<class T> int BaseWithoutNewTypes<T>::initInBase = [] { std::cout << "4 initInBase template without new types" << std::endl; return 10; }(); struct DerivedWithoutTypes : BaseWithoutNewTypes<int> {}; // 5 MSVC specific template<typename T> struct BaseForMSVC { static int initInBase; constexpr static int *unusedAddr = &initInBase; }; template<class T> int BaseForMSVC<T>::initInBase = [] { std::cout << "5 initInBase MSVC" << std::endl; return 10; }(); struct DerivedMSVC : BaseForMSVC<int> {}; int main () { // 2 Derived d; // 3 DerivedT dt; // 4 DerivedWithoutTypes dwt; // 5 DerivedMSVC dmsvc; }
run
|
edit
|
history
|
help
0
program_solution_3
C++ Macro overload
problem_soultion2
C++ move/copy constructor and assignment demo
Iterate_Variac_Template
hangman
std::is_same doesn't check for calling convention
dump_own_process.cpp
accessing private of different type of template
cv4_template