如何解决错误:请求'*&it-> __ gnu_cxx :: __ normal_iterator <st **,std :: vector <st *>> :: operator->',*it->中的成员'getdata' getdata;
这是我尝试创建N对象并将其存储到向量数组中的代码。并尝试使用Vector类显示每个对象的数据。但是编译器抛出一个错误。如何解决????
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct st SLL;
struct st
{
int id;
char Name[10];
void setdata();
void getdata();
SLL * creatObject();
};
void SLL :: setdata()
{
cout << "Enter the Data\n";
cin >> id>> Name;
}
void SLL:: getdata()
{
cout << id << " " << Name << endl;
}
SLL * SLL:: creatObject()
{
SLL * newObject = new SLL();
newObject->setdata();
newObject->getdata();
return newObject;
}
int main()
{
std::vector<SLL*> v;
for (int i = 0; i < 3; ++i)
{
v.push_back(creatObject());
}
std::vector<SLL*> ::iterator it ;
for(it = v.begin(); it != v.end() ;it++)
{
*(it)->getdata();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。