问题描述
- vector容器中传入类的指针,增加元素和遍历
- 我写下代码说明一下:
class A
{
public:
A()
{
Pos = 0;
WaitingPeople = 0;
strName= """";
}
~A(){}
private:
size_t Pos;
size_t WaitingPeople;
string strName;
}
class B
{
private:
vectorvecA;
public:
void Add(A* a)
{
vecA.push_back(a); //如何增加一个成员这样对么?}
}
int main()
{
//如何调用,下面的代码是我自己写的,帮忙看下有什么地方不对的。
B b;
A a1 = new A();
for(vector<A>::iterator it = b.vecA.begin(); it != b.vecA.end(); ++it)
{
cout<<*it<<endl;
}
delete a1;
}
时间: 2024-10-01 03:51:50