关于C++编译静态模板成员数据出错 Too few template-parameter-lists
来源:互联网 发布:火车票抢购软件 编辑:程序博客网 时间:2024/06/02 03:38
学习侯捷大师《STL源码剖析》的时候
在用GCC编译P27的 __STL_STATIC_TEMPLATE_MEMBER_BUG 测试代码:
01 #include <iostream>02 using namespace std;0304 template <typename T>05 class TestClass06 {07 public:08 static int data;09 };1011 int TestClass<int>::data = 1;12 int TestClass<char>::data = 2;1314 int main()15 {16 cout<<TestClass<int>::data<<endl17 <<TestClass<char>::data<<endl;1819 TestClass<int> obji;20 TestClass<char> objc;2122 cout<<obji.data<<endl23 <<objc.data<<endl;2425 return 0;26 }
用GCC编译时出错:Too few template_parameter-lists
主要的原因是不同时期的编译器编译方式不同,作如下修改后便能顺利编译:
01 #include <iostream>02 using namespace std;0304 template <typename T>05 class TestClass06 {07 public:08 static int data;09 };1011 template<> int TestClass<int>::data = 1; //add template<>告诉编译器这是模板实作的12 template<> int TestClass<char>::data = 2; //add template<>告诉编译器这是模板实作的1314 int main()15 {16 cout << TestClass<int>::data << endl17 << TestClass<char>::data << endl;1819 TestClass<int> obji;20 TestClass<char> objc;2122 cout << obji.data << endl23 << objc.data << endl;2425 return 0;26 }
这样便能顺利编译执行了。
记录轨迹,分享思想,你我共同成长。--纯白色.C
0 0
- 关于C++编译静态模板成员数据出错 Too few template-parameter-lists
- c++ 模板 迭代器 使用问题解决方法(too few template-parameter-lists)
- IAR编译出错:Error[Pe165]: too few arguments in function call
- 手动编译memcached时遇到memcache.c error: too few arguments to function ‘zend_list_insert’的解决方法
- Template template parameter(模板参数) example
- uvc_v4l2_ioctl.h 提示出错 too few arguments to function ‘v4l_printk_ioctl’
- c++ template - 成员模板
- 成员模板(member template)
- C++static静态数据成员
- C++: typename in a template template parameter
- 关于模板类中静态成员
- fuse_trash.c:119: error: too few arguments to function 'hdfsDelete'
- 关于静态数据成员与静态成员函数的…
- static(c++)静态数据成员和静态成员函数
- c++:静态函数成员与静态数据成员
- 3-6 静态数据成员与静态成员函数(c++)
- C++_静态数据成员和静态成员函数
- 再看成员模板---member template
- 【Python基础】Python面向对象 - 7 - Mixin & MRO
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- 从mysql数据库生成javabean
- freeMarker格式化日期
- Android Studio教程04-导入Eclipse项目到AndroidStudio(包括导入第三方Project项目(不是jar包形式))
- 关于C++编译静态模板成员数据出错 Too few template-parameter-lists
- [POJ 1733]Parity game[并查集]
- HighCharts dynamic-master-detail多线解决方案
- Java工厂模式
- XMPP协议简介+扩展协议
- POJ_2112_Optimal Milking(最大流+二分)
- maven3 快速入门指南
- 复杂TableView在iOS上的性能优化
- Mongodb数据 导入导出数据 导出工具mongoexport和导入工具mongoimport介绍