64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
using namespace std;
struct A
{
int a;
int b;
};
A* GetStr(vector<A> &ivec)
{
return &ivec.at(0);
};
int main()
{
A temp;
temp.a = 1;
temp.b = 2;
vector<A> ivec;
ivec.push_back(temp);
A *temp2 = GetStr(ivec);
cout << temp2->a << temp2->b << endl;//返回12
getchar();
return 0;
}
void GetStr(A** aA) { //函数内改变传递来的指针,用A**
*aA = &arrA.GetAt(1);
}
int main() {
A* test = NULL;
GetStr(&test);
test->a = 10;
test->b = 11;
}
int i = 10;
struct A aa = arrA.GetAt(i);
aa.a = 100;
arrA.SetAt(i, aa);