C++ 我的test.cpp文件正在使用默认运算符<&书信电报;;什么';这个签名怎么了?
在过去的30分钟里,我一直在试图找出这个问题的症结所在: 从.h文件:C++ 我的test.cpp文件正在使用默认运算符<&书信电报;;什么';这个签名怎么了?,c++,io,operators,ostream,C++,Io,Operators,Ostream,在过去的30分钟里,我一直在试图找出这个问题的症结所在: 从.h文件: // H/T sent. d-linked list Set #ifndef SET_H #define SET_H #include <iostream> #include <string> using namespace std; typedef string ELEMENT_TYPE; // a set for string elements class Set{ private:
// H/T sent. d-linked list Set
#ifndef SET_H
#define SET_H
#include <iostream>
#include <string>
using namespace std;
typedef string ELEMENT_TYPE; // a set for string elements
class Set{
private:
struct Elem {
ELEMENT_TYPE info;
Elem *prev, *next;
};
Elem *_head, *_tail;
int _size;
void copyCode(const Set & v);
void destructCode();
ostream& dump(ostream& out, const Set &v);
public:
Set();
Set(const Set &rhs);
~Set();
Set& operator=(const Set &rhs);
bool insert(ELEMENT_TYPE);
bool erase(ELEMENT_TYPE);
void clear();
int size() const { return _size; }
bool find(ELEMENT_TYPE) const;
class Iterator{
private:
Elem * _cur;
public:
Iterator(){}
explicit Iterator( Elem* );
Iterator operator++( int );
Iterator operator++();
Iterator operator--( int);
Iterator operator--();
bool operator==( const Iterator& rhs );
bool operator!=( const Iterator& rhs );
ELEMENT_TYPE& operator*();
ostream& operator<< ( ostream& );
};
Iterator begin() const;
Iterator end() const;
friend ostream& operator<< (ostream&, Set&);
};
bool operator==(const Set&, const Set&);
bool operator!=(const Set&, const Set&);
Set operator&(const Set&, const Set&);
Set operator|(const Set&, const Set&);
#endif
这显然不是我在我的operator中提供的信息你不能实现operator对我来说很好。我猜(A)你的集合中的数据实际上是“3,2,1”,因为
set::insert
被破坏了,或者(B)你编程你的迭代器以相反的方向进行迭代。因为你没有发布A,所以必须关闭它,直到它被编辑为可回答。对不起的:(你什么意思是无法回答?缺少什么?你问题中的代码看起来很完美。这里没有问题。问题在于不在这里的代码。单击我之前评论中的链接,它应该会告诉你如何编写更好的、可回答的问题。@MooingDuck我想我们可能会相互混淆,我已经包含了所有内容这在我的代码中似乎是相关的。其他内容是我的插入和删除方法、构造函数等。如果缺少某些内容,这可能是因为我没有它,这可能是问题所在。我的问题是,此代码实际上没有输出“\u cur->info”+“\n”,只是“\u cur->info”很明显,我没有正确地写下签名。遗漏了什么有助于澄清不存在的签名?
string& Set::Iterator::operator*(){
return _cur -> info;
}
ostream& Set::Iterator::operator<< ( ostream& os ){
os << _cur -> info << "\n";
return os;
}
Set s1;
s1.insert( "1" );
s1.insert( "2" );
s1.insert( "3" );
cout << "Hi\n";
Set::Iterator it = s1.begin();
while( it != s1.end() ){
cout << *it;
it++;
}
cout << "Bye\n";
Hi
321Bye
ostream& operator<< (this, ostream& );
ostream& operator<< ( ostream& str, iterator& iter );
Set::Iterator it = s1.begin();
while( it != s1.end() ){
cout << *it;
it++;
}
Set::Iterator it = s1.begin();
while( it != s1.end() ){
cout << it;
it++;
}