您的位置:程序门 -> c/c++ -> c++ 语言



非常奇怪的模版类成员函数重载


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


非常奇怪的模版类成员函数重载
发表于:2008-01-23 09:18:21 楼主
tempclass.h:  
#ifndef   __tempclass_h__
#define   __tempclass_h__

#if   _msc_ver   >   1000
#pragma   once
#endif   //   _msc_ver   >   1000

#include   <bitset>
#include   <vector>
using   namespace   std;
template <size_t   _n>
class   ctempclass    
{
typedef   bitset <_n> bit;
typedef   vector <bit   > vbit;
typedef   vector <vbit   > vvbit;
public:
ctempclass(){}
~ctempclass(){}
int   and(vbit   vb)
{
return   0;
}
int   and(vvbit   vvb)
{
return   0;
}
};

#endif   //   #ifndef   __tempclass_h__

main.cpp:
#pragma   warning(disable:4786)

#include   "tempclass.h"

int   main()
{
vector <bitset <32>   > vb;
ctempclass <32> tc;
  tc.and(vb);
return   0;
}
错误如下:
compiling...
testbitset.cpp
c:\documents   and   settings\dejing.yang\testbitset\tempclass.h(29)   :   error   c2535:   'int   __thiscall   ctempclass <_n> ::and(class   std::vector <class   std::bitset <_n> ,class   std::allocator <class   std::bitset <_n>   >   > )'   :   member   function   already   defined   or   declared
                c:\documents   and   settings\dejing.yang\testbitset\tempclass.h(24)   :   see   declaration   of   'and'
                c:\documents   and   settings\dejing.yang\testbitset\tempclass.h(32)   :   see   reference   to   class   template   instantiation   'ctempclass <_n> '   being   compiled


error   EXECuting   cl.exe.

testbitset.exe   -   1   error(s),   0   warning(s)
发表于:2008-01-23 09:28:151楼 得分:0
就上面这些吗,用vs2005没错
发表于:2008-01-23 09:34:212楼 得分:0
int       and(vvbit       vb)
{
return       0;
}

看你那声明参数应该是   bit   vb才对啊。。
发表于:2008-01-23 09:52:183楼 得分:0
2003也没有错误。
发表于:2008-01-23 09:52:184楼 得分:0
2003也没有错误。
发表于:2008-01-23 09:58:475楼 得分:0
dev   c++也编译成功。lz试试rebuild   all?
发表于:2008-01-23 11:48:236楼 得分:0
不好意思,我用的是vc6.0,,有谁帮下忙哦
发表于:2008-01-23 11:57:387楼 得分:0
许多高手说:遇到这类问题,扔掉vc6。
发表于:2008-01-23 12:33:488楼 得分:0
我也想扔掉,但工程很大,一时不好转啊,


快速检索

最新资讯
热门点击