specialization of template.... in different namespace的解决
来源:互联网 发布:淘宝网 ie8不能登录 编辑:程序博客网 时间:2024/05/17 23:28
原文来自http://blog.csdn.net/coder_xia/article/details/6764777
代码来自DTL文档index.htm
- struct Example
- { // tablename.columnname:
- int exampleInt; // DB_EXAMPLE.INT_VALUE
- string exampleStr; // DB_EXAMPLE.STRING_VALUE
- double exampleDouble; // DB_EXAMPLE.DOUBLE_VALUE
- long exampleLong; // DB_EXAMPLE.EXAMPLE_LONG
- TIMESTAMP_STRUCT exampleDate; // DB_EXAMPLE.EXAMPLE_DATE
- };
struct Example{ // tablename.columnname:int exampleInt; // DB_EXAMPLE.INT_VALUEstring exampleStr; // DB_EXAMPLE.STRING_VALUEdouble exampleDouble; // DB_EXAMPLE.DOUBLE_VALUElong exampleLong; // DB_EXAMPLE.EXAMPLE_LONGTIMESTAMP_STRUCT exampleDate; // DB_EXAMPLE.EXAMPLE_DATE};这一段上次还碰到过TIMESTAMP_STRUCT未定义的情况,纯属意外
- template<>class dtl::DefaultBCA<Example>
- {
- public:
- void operator()(BoundIOs &cols, Example &rowbuf)
- {
- cols["INT_VALUE"] == rowbuf.exampleInt;
- cols["STRING_VALUE"] == rowbuf.exampleStr;
- cols["DOUBLE_VALUE"] == rowbuf.exampleDouble;
- cols["EXAMPLE_LONG"] == rowbuf.exampleLong;
- cols["EXAMPLE_DATE"] == rowbuf.exampleDate;
- }
- };
template<>class dtl::DefaultBCA<Example>{public: void operator()(BoundIOs &cols, Example &rowbuf) { cols["INT_VALUE"] == rowbuf.exampleInt; cols["STRING_VALUE"] == rowbuf.exampleStr; cols["DOUBLE_VALUE"] == rowbuf.exampleDouble; cols["EXAMPLE_LONG"] == rowbuf.exampleLong; cols["EXAMPLE_DATE"] == rowbuf.exampleDate;}};在编译的时候,代码中只有个输出helloworld,错误提示如下:
error: specialization of ‘template<class DataObj> class dtl::DefaultBCA’ in different namespace
参考1:http://womble.decadent.org.uk/c++/template-faq.html#specialise-ns faq,是个很和谐的东东啊
Q: Whatdoes the error message "specialization of ... in different namespace"mean?
A: Thismeans that the code appears to be defining a template specialisation, but itnames a template that was defined in a different namespace. This is not valid,though some older versions of g++ accept it. Every declaration for a templatemust be placed in the same namespace, just like repeated declarations of anyother named entity.
参考2:http://gcc.gnu.org/ml/gcc/2005-04/msg00134.html
The error is that the specialisation isin a different namespace from the declaration, not the definition.
//他的观点是声明与模板的具体化在不同的命名空间了
先不去深究,直接上楼主的解决方案:
修改具体化代码
- template<> class DefaultBCA<Example>
template<> class DefaultBCA<Example>
为:
- class Test:public DefaultBCA<Example>
class Test:public DefaultBCA<Example>即具体化模板类的时候,用类继承。
注意点:
1) template<>,也可以写在class那行的第二行,如果没有,也许会导致too few template-parameter-lists的错误;可以参考
http://hi.baidu.com/huangyunict/blog/item/5b50bdd658b8f32206088bd5.html
参考http://forum.ubuntu.org.cn/post-99237.html ,貌似是gcc版本的问题
2) 这里为什么要用继承,我也不知道,只是改了之后编译能过,起码先没错。
说明下:
这是楼主经过查找和测试之后改的,由于对模板不是很熟,所以也搜了部分基础的东东,就没贴上来,其他主要参考的链接都给出了,应该够具体了。希望对以后有同样问题的人有用,不过只是对楼主自己遇到的情况而言,不保证其他情况。
- specialization of template.... in different namespace的解决
- specialization of template.... in different namespace的解决
- linux template error: explicit specialization in non-namespace scope
- Template Specialization
- template specialization
- Template Specialization and Partial Template Specialization
- 模板特殊化(Template specialization)
- template specialization on template class
- C++ 函数模板的特化(Function Template Specialization)
- befriending a template in another namespace
- 模板特化(template specialization)
- C++ Template Specialization (模板特化)
- 解决The type or namespace name \'XXXX\' does not exist in the namespace \'XXXXXXXXX\' 的错误
- The type or namespace name 'Zhaopin' does not exist in the namespace 'LMSoft' 问题的解决
- The Different Format of Date in English
- Protocols in different layers of a network
- Different types of keystore in Java -- JKS
- Different types of keystore in Java -- PKCS12
- 基于 RMAN 的同机数据库克隆
- Undefined symbols for architecture armv7
- mysql:ADO连接mysql数据库,驱动程序和ODBC数据源问题
- ACM 数星星
- this class is not key value coding-compliant for the key
- specialization of template.... in different namespace的解决
- 学习arm裸机程序
- android颜色配置表--表二
- Makefile 中:= ?= += =的区别
- 读书笔记1——《HTTP权威指南》
- 比较具有从google earth下载影像并拼接功能的两个软件getscreen VS sggs
- hdu2119(二分图+最小点覆盖+匈牙利算法)
- 将tomcat安装为服务
- iOS应用开发最佳实践