- 论坛徽章:
- 0
|
本帖最后由 Redshadows 于 2013-08-19 16:33 编辑
test.h
- #pragma once
- namespace TT
- {
- struct No
- {
- int i;
- };
- struct Test;
- void nothing(Test &test);
- struct Test
- {
- friend void nothing(Test &test);
- template <typename T> void show(const T& tt);
- // template <> void show(const int& tt);
- void show1();
- };
- }
复制代码 test.cpp- namespace TT;
- template<typename T>
- void Test::show(const T& tt)
- {
- cout << "test" << endl;
- }
- template<>
- void TT::Test::show(const TT::No& tt)
- {
- cout << "haha" << endl;
- }
- void Test::show1()
- {
- show(1);
- }
复制代码 main.cpp- #include "test.h"
- int main()
- {
- TT::Test test;
- int a = 0;
- test.show1();
- nothing(test);
- return 0;
- }
复制代码 编译后提示
test.cpp:14: error: specialization of ‘template<class T> void TT::Test::show(const T&)’ in different namespace
test.h:17: error: from definition of ‘template<class T> void TT::Test::show(const T&)’
test.cpp:16: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/ccDOpYyR.out file, please attach this to your bugreport.
Traceback (most recent call last):
File "/usr/share/apport/gcc_ice_hook", line 34, in <module>
pr.write(open(apport.fileutils.make_report_path(pr), 'w'))
IOError: [Errno 13] Permission denied: '/var/crash/_usr_lib_gcc_i486-linux-gnu_4.3.3_cc1plus.1000.crash'
求指点。
|
|