64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
#include <string>
#include <memory>
#include <vector>
typedef struct TLocalParameterData{
//局部坐标系名称
string strName;
//对应的全局坐标系
string strCounterpart;
//是否是4参数
bool Is4Paras;
double X;
double Y;
double dK;
double Ez; //εz
}TLoc4ParasData;
struct TLoc7ParasData : TLocalParameterData{
double Z;
double Ex;
double Ey;
};
int main(int argc, char *argv[])
{
//普通指针
TLocalParameterData* p[10];
TLoc7ParasData a;
a.strName = "aaaa";
a.Z = 999;
p[0] = (TLocalParameterData*)&a;
cout<<((TLoc7ParasData*)p[0])->Z<<endl;
//智能指针
std::vector<std::auto_ptr<TLocalParameterData> > pSL;
std::auto_ptr<TLoc7ParasData> pL(new TLoc7ParasData);
pL->strName = "bbb";
pSL.push_back((std::auto_ptr<TLocalParameterData>)pL);
cout<<pSL[0]->strName<<endl;
return 0;
}
void CPointerDlg::OnButton3()
{
// TODO: Add your control notification handler code here
/*
上面(OnButton2)那个
std::auto_ptr<int> s[10];
不是还得要写个10吗,不动态,那就用下面这个
*/
std::vector<std::auto_ptr<int> > s;
for (int i=0; i<10; i++)
{
//std::auto_ptr<int> p(new int(i));
s.push_back(std::auto_ptr<int>(new int(i)));
}
CString strTemp, strResult;
for (i=0; i<10; i++)
{
strTemp.Format(_T("%d, "), *s[i]);
strResult += strTemp;
}
GetDlgItem(IDC_STATIC_TEXT)->SetWindowText(strResult);
}