
error C2679: 二进制“<<”: 没有找到接受“ID”类型的右操作数的运算符(或没有可接受的转换)
template<classA>classStack:publicList<A>{public:voidpush(Ad);voidpop(A&e);voidshow();...
template <class A>
class Stack:public List<A>
{
public:
void push(A d);
void pop(A &e);
void show();
void tostack(Queue<A> p);
};
template <class A>
ostream &operator<<(ostream &stream,List<A> x)
{
int i;
for(i=1;i<=x.GetCount();i++){
stream<<x.GetAt(i)<<" ";
}
return stream;
}
class ID
{
public:
Stack<int> id;
CString kw;
int length;
template <class A> //还有这个 特别怪异 到底要怎么弄才行啊
friend ostream& operator<< (ostream &stream,ID x);
};
template <class A> //我觉得是这个和上面那个模板的问题 但我两个都删除过都不行
ostream &operator<< (ostream &stream,ID x)
{
stream<<x.id<<" "<<x.kw;
return stream;
}
由于全部程序太长了所以上面省了很多东西。。 求高手救命。。。我快想死了。。。 展开
class Stack:public List<A>
{
public:
void push(A d);
void pop(A &e);
void show();
void tostack(Queue<A> p);
};
template <class A>
ostream &operator<<(ostream &stream,List<A> x)
{
int i;
for(i=1;i<=x.GetCount();i++){
stream<<x.GetAt(i)<<" ";
}
return stream;
}
class ID
{
public:
Stack<int> id;
CString kw;
int length;
template <class A> //还有这个 特别怪异 到底要怎么弄才行啊
friend ostream& operator<< (ostream &stream,ID x);
};
template <class A> //我觉得是这个和上面那个模板的问题 但我两个都删除过都不行
ostream &operator<< (ostream &stream,ID x)
{
stream<<x.id<<" "<<x.kw;
return stream;
}
由于全部程序太长了所以上面省了很多东西。。 求高手救命。。。我快想死了。。。 展开
1个回答
展开全部
我觉得吧,你把ID类里面两个template去掉应该没有问题的吧
--------------------------------------------------------------------------------
你就先测试Stack试试,先注释掉ID类呢?
--------------------------------------------------------------------------------
你就先测试Stack试试,先注释掉ID类呢?
追问
那就提示error LNK2005: "class std::basic_ostream > & __cdecl operator > &,class ID)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@VID@@@Z) 已经在 main.obj 中定义
追答
因为你里面有好多东西没给,改了我好久。。。 把下面ID的两个模板去掉就可以了
我改成我能编译通过了
全都是List啊 Queue啊 GetAt啊 GetCount这些你自己定义的方法,反正我改成vector什么的去掉那两个模板,然后就没有报错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询