C++ 容器列表,我在for循环中得到错误
我想知道为什么我不能在这个方法中使用for循环,我在我的replace和insert方法中使用它,但是在听说for循环行中出现了一些错误C++ 容器列表,我在for循环中得到错误,c++,list,containers,C++,List,Containers,我想知道为什么我不能在这个方法中使用for循环,我在我的replace和insert方法中使用它,但是在听说for循环行中出现了一些错误 Contact return(const list<Contact> &listOf, int index) { for(list<Contact>::iterator it = listOf.begin(); it != listOf.end(); it++){ } return Contact(
Contact return(const list<Contact> &listOf, int index) {
for(list<Contact>::iterator it = listOf.begin(); it != listOf.end(); it++){
}
return Contact(); //dummy return. don't know what to do here
}
Contact return(const list&listOf,int index){
for(list::iterator it=listOf.begin();it!=listOf.end();it++){
}
return Contact();//虚拟返回。不知道在这里做什么
}
如果您能提供一些帮助,帮助我如何实现代码,以及我需要返回什么信息,我将不胜感激
我的意思是,我知道如何检查if station以获得正确的对象,但我不知道在if station中我必须做什么,以及在返回时写什么而不是“Contact();”使用常量迭代器获得常量列表
Contact return_function(const list<Contact> &listOf, int index) {
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
}
return Contact(); //dummy return
}
Contact return_函数(const list&listOf,int index){
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
}
return Contact();//虚拟返回
}
编辑。修复了其他人指出的函数名…对常量列表使用常量迭代器
Contact return_function(const list<Contact> &listOf, int index) {
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
}
return Contact(); //dummy return
}
Contact return_函数(const list&listOf,int index){
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
}
return Contact();//虚拟返回
}
编辑。修复了其他人指出的函数名…对常量列表使用常量迭代器
Contact return_function(const list<Contact> &listOf, int index) {
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
}
return Contact(); //dummy return
}
Contact return_函数(const list&listOf,int index){
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
}
return Contact();//虚拟返回
}
编辑。修复了其他人指出的函数名…对常量列表使用常量迭代器
Contact return_function(const list<Contact> &listOf, int index) {
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
}
return Contact(); //dummy return
}
Contact return_函数(const list&listOf,int index){
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
}
return Contact();//虚拟返回
}
编辑。修复了其他人指出的函数名…您需要
const\u迭代器
,因为listOf
是const
Contact return(const list<Contact> &listOf, int index) {
// ^^^^^---const container-----<
// ^
// const_iterator--vvvvvv because of ->|
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
Contact return(const list&listOf,int index){
//^^^^---const容器-----<
// ^
//常量迭代器--vv因为->|
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
另外,您必须重命名函数,
return
是一个关键字。您需要const\u迭代器,因为listOf
是const
Contact return(const list<Contact> &listOf, int index) {
// ^^^^^---const container-----<
// ^
// const_iterator--vvvvvv because of ->|
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
Contact return(const list&listOf,int index){
//^^^^---const容器-----<
// ^
//常量迭代器--vv因为->|
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
另外,您必须重命名函数,return
是一个关键字。您需要const\u迭代器,因为listOf
是const
Contact return(const list<Contact> &listOf, int index) {
// ^^^^^---const container-----<
// ^
// const_iterator--vvvvvv because of ->|
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
Contact return(const list&listOf,int index){
//^^^^---const容器-----<
// ^
//常量迭代器--vv因为->|
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
另外,您必须重命名函数,return
是一个关键字。您需要const\u迭代器,因为listOf
是const
Contact return(const list<Contact> &listOf, int index) {
// ^^^^^---const container-----<
// ^
// const_iterator--vvvvvv because of ->|
for(list<Contact>::const_iterator it = listOf.begin(); it != listOf.end(); it++){
Contact return(const list&listOf,int index){
//^^^^---const容器-----<
// ^
//常量迭代器--vv因为->|
for(list::const_迭代器it=listOf.begin();it!=listOf.end();it++){
此外,您必须重命名函数,return
是一个关键字。您不能将关键字用作函数名。请澄清关于“我必须返回什么”的问题我的意思是我知道如何检查witch on witch index我想用if获取对象。但是我不知道在if statemt中我必须做什么。你不能使用关键字作为函数名。请澄清关于“我必须返回什么”的问题我的意思是我知道如何检查witch on witch index我想用if获取对象。但是我不知道在if statemt中我必须做什么。你不能使用关键字作为函数名。请澄清关于“我必须返回什么”的问题我的意思是我知道如何检查witch on witch index我想用if获取对象。但是我不知道在if statemt中我必须做什么。你不能使用关键字作为函数名。请澄清关于“我必须返回什么”的问题我的意思是,我知道如何在巫婆索引上检查巫婆,我想用if获取对象。但我不知道在if状态下我该怎么做。我知道我只是从我的语言中尝试:)我知道我只是从我的语言中尝试:)我知道我只是从我的语言中尝试:)我知道我只是从我的语言中尝试:)