在泛型设计中遇到了一个难题,关于模板推演的,高手入!

fireseed 2008-07-28 01:56:40
template <typename Type>
class CMatrix
{
public:
// 下面的这个函数仅仅用于输出,后两个模板参数在其它的函数中是用不上的,所以不想放在类的模板列表里
template < typename Type, typename _Elem, typename _Traits >
inline void Output( const _Elem *pFormat, basic_ostream<_Elem, _Traits > &OutStream );
};

template < typename Type, typename _Elem, typename _Traits >
inline void CMatrix<Type>::Output( const _Elem *pFormat, basic_ostream<_Elem, _Traits > &OutStream )
{
}

// 调用:
CMatrix mat;
mat.Output( 0, cout ); // 出错

VC.net 2005出错信息:
error C2244: “CMatrix<Type>::Output”: 无法将函数定义与现有的声明匹配
定义
'void CMatrix<Type>::Output(const _Elem *,std::basic_ostream<_Elem,_Traits> &)'
现有声明
'void CMatrix<Type>::Output(const _Elem *,std::basic_ostream<_Elem,_Traits> &)'

请高手指点在此过程中的模板推演过程出了什么问题导至这样的错误?欢迎大家讨论!
拜谢!
...全文
65 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
.....
baihacker 2008-07-28
  • 打赏
  • 举报
回复
呵...
baihacker 2008-07-28
  • 打赏
  • 举报
回复
能上更多的代码就好了
fireseed 2008-07-28
  • 打赏
  • 举报
回复
对了,对了!

原来是粗心大意,呵呵,真是不好意思!谢谢大侠!
fireseed 2008-07-28
  • 打赏
  • 举报
回复
改了,一样的结果,出同样的错
baihacker 2008-07-28
  • 打赏
  • 举报
回复
你的语法错了吧?

template <typename Type> 
class CMatrix
{
public:
// 下面的这个函数仅仅用于输出,后两个模板参数在其它的函数中是用不上的,所以不想放在类的模板列表里
template < typename Type, typename _Elem, typename _Traits >
inline void Output( const _Elem *pFormat, basic_ostream <_Elem, _Traits > &OutStream );
};

template < typename Type, typename _Elem, typename _Traits >
inline void CMatrix <Type>::Output( const _Elem *pFormat, basic_ostream <_Elem, _Traits > &OutStream )
{
}

改成下面的:
class CMatrix
{
public:
// 下面的这个函数仅仅用于输出,后两个模板参数在其它的函数中是用不上的,所以不想放在类的模板列表里
template < typename Type, typename _Elem, typename _Traits >
inline void Output( const _Elem *pFormat, basic_ostream <_Elem, _Traits > &OutStream );
};

template <typename _Elem, typename _Traits >
inline void CMatrix <Type>::Output( const _Elem *pFormat, basic_ostream <_Elem, _Traits > &OutStream )
{
}


template <typename Type>
template <typename _Elem, typename _Traits >
inline void CMatrix <Type>::Output( const _Elem *pFormat, basic_ostream <_Elem, _Traits > &OutStream )
baihacker 2008-07-28
  • 打赏
  • 举报
回复
mark一下.

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧