1 #include <vector> 2 #include <deque> 3 #include <algorithm> 4 #include <iostream> 5 #include <ostream> 6 #include <iterator> 7 using namespace std; 8 template <typename T> 9 class conststaticconstant 10 { 11 public://class内含const static integral data(整数型别) member,那么就可以直接赋初值 12 static const int _datai = 5; 13 static const long _datal = 3L; 14 static const char _datac = ‘c‘; 15 //static const double _datad = 8.88;//error: ‘constexpr‘ needed for in-class initialization of static data member ‘const float conststaticconstant<T>::_dataf‘ of non-integral type [-fpermissive] 16 //static const float _dataf = 9.9; 17 // void operator ()(const T& elem){ 18 // cout << elem << ‘ ‘; 19 // } 20 }; 21 int main( ) 22 { 23 cout << conststaticconstant<int>::_datai << endl; 24 cout << conststaticconstant<int>::_datal << endl; 25 cout << conststaticconstant<int>::_datac << endl; 26 return 0; 27 }
原文:http://www.cnblogs.com/guxuanqing/p/6670901.html