我一直试图传递一个类的实例" person"一个函数来打印该列表的包含,但我不确定如何解决错误。
Program::Program()
{
list<Person*> people;
list<Person*>::iterator iter;
cout << "Hello, Please Enter The Number Of People " << endl;
cin >> Maxpeople;
{
for (int i = 0; i < Maxpeople; i++)
{
Person *p1 = new Person();
cin.ignore();
cout << "Hello " << endl;
cout << "Please Enter The Name Of Person " << i + 1 << endl;
getline(cin, input);
p1->setname(input);
people.push_back(p1);
}
Program P;
P.print(people, iter); <----Call Print Function
getline(cin, input);
}
//header
void print(list<Person*> p, list<Person*>::iterator i);
//header
void Program::print(list<Person*> p, list<Person*>::iterator i)
{
for (i = p.begin(); i != p.end(); i++)
{
cout << (*i)->getname() << endl;
}
}
严重级代码描述项目文件行抑制状态
错误C2061语法错误:标识符&#39; list&#39; App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26
错误C2061语法错误:标识符&#39; list&#39; App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26
错误C2511&#39; void Program :: print(std :: list&gt;,std :: _ List_iterator&gt;&gt;)&#39;:重载的成员函数未在&#39; Program&#39;中找到App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ app1.cpp 55
错误C2061语法错误:标识符&#39; list&#39; App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26
我相信看错误c2061 / 2511我没有正确定义列表的类型。非常感谢任何帮助,谢谢。
---更新一个-----
严重级代码描述项目文件行抑制状态
错误C2065&#39; Person&#39;:未声明的标识符App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26
错误C2059语法错误:&#39;&gt;&#39; App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26
错误C2955&#39; std :: list&#39;:使用类模板需要模板参数列表App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26个
错误C2976&#39; std :: list&#39;:模板参数太少App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ stdafx.h 26 >
警告C4717&#39; Program :: Program&#39;:递归所有控制路径,函数将导致运行时堆栈溢出App1 c:\ users \ alasdair \ documents \ visual studio 2015 \ projects \ drawstudio \ c ++ fun \ app1 \ app1.cpp 53
答案 0 :(得分:0)
所以我弄清楚我做错了什么(虽然我使用的是字符串列表而不是自定义类),因为回复的人说我没有正确地通过引用传递。对于任何感兴趣的人,这是我的代码。显然,您可以使用javax.servlet.jsp.JspException: ServletException
来检索下一个值。
非常感谢你的帮助。
====主要====
pop_front()
====部首====
#include "stdafx.h"
int main()
{
std::string input = "";
std::list<std::string> people;
people.push_back("Harry");
printlist(&people);
std::cin >> input;
}
void printlist(std::list<std::string> *mylist)
{
std::list<std::string>::iterator myiterator;
for (myiterator = mylist->begin(); myiterator != mylist->end();myiterator++)
{
std::cout << mylist->front() << std::endl;
}
}