我试图插入元素设置“教师”。教师是结构,学校的一部分。学校结构在另一个叫做城镇的地方。我试图把老师“绿色”放到学校里,“布朗”是校长。我用find来找到学校,但我不能让他进来。运营商<,==被定义为比较校长。通过迭代器插入元素C++
bool operator<(const School& l, const School& r){
return (l.headmaster) < (r.headmaster);
}
bool operator==(const School& l, const School& r){
return (l.headmaster) == (r.headmaster);
}
struct School {
string headmaster;
set <string> teachers;
};
set<School>::iterator it;
set <School> town;
// now I alocated few schools and insert them into town,
School *pSchool = new School(): // i will use pSchool to find school with brown as headmaster
pSchool > headmaster = "Brown"; //
it = rozvrh.find(*pSchool);
cout << it->headmaster // gives Brown
it->teachers.insert("Green"); /// error
编辑..错误
|| === ulohaa1,调试=== | /home/ulohaa1/main.cpp||在函数'布尔变换(常量字符*,常量字符*)':| /home/ulohaa1/main.cpp|84|错误:没有匹配函数调用'std :: set> :: insert(std :: string &)const'| /home/michal/Desktop/prog/ulohaa1/main.cpp|84|note:考生是:| /usr/include/c++/4.6/bits/stl_set.h|407|note:std :: pair,_Compare,typename _Alloc :: rebind < _Key> :: other> :: const_iterator,bool> std :: set < _Key,_Compare,_Alloc> :: insert(const value_type &)[with _Key = std :: basic_string,_Compare = std :: less>,_Alloc = std :: allocator>,typename std :: _ Rb_tree < _Key,_Key,std :: _ Identity < _Key>,_Compare,typename _Alloc :: rebind < _Key> :: other> :: const_iterator = std :: _ Rb_tree_const_iterator>,std :: set < _Key,_Compare,_Alloc> :: value_type = std :: basic_string ] | /usr/include/c++/4.6/bits/stl_set.h|407|note:对于隐式'this'参数从'const std :: set>'到'std :: set>'|没有已知的转换。 /usr/include/c++/4.6/bits/stl_set.h|444|note:std :: set < _Key,_Compare,_Alloc> :: iterator std :: set < _Key,_Compare,_Alloc> :: insert(std :: set < _Key,_Compare,_Alloc> :: const_iterator,const value_type )[with _Key = std :: basic_string,_Compare = std :: less>,_Alloc = std :: allocator>,std :: set < _Key, _Compare,_Alloc> :: iterator = std :: _ Rb_tree_const_iterator>,std :: set < _Key,_Compare,_Alloc> :: const_iterator = std :: _ Rb_tree_const_iterator>,std :: set < _Key,_Compare,_Alloc> :: value_type =性病:: basic_string的] | /usr/include/c++/4.6/bits/stl_set.h|444|note:候选人需要2个参数,1个提供| /usr/include/c++/4.6/bits/stl_set.h|464|note:template void std :: set :: insert(_InputIterator,_InputIterator)[with _InputIterator = _InputIterator,_Key = std :: basic_string,_Compare = std :: less>,_Alloc = std :: allocator>] | || ===构建完成:7个错误,0个警告=== |
THX您的帮助球员
C++是大小写敏感的,因此线{学校* pSchool =新学校():}不应该编译(更不要说冒号在行尾) – Andy
@安迪,除非'学校'是秘密地继承'学校',但从OP的问题来看,这不太可能 – yizzlez
@awesomeyi同意。 OP可以澄清, – Andy