|
안녕하세요.. 초보자 입니다.
STL 관련 하여.... 책보면서.. 바꾸면서 이거 저거 해보려고 하는데..
에러가 나서 이렇게 여쭤보게 되었습니다.
두가지 여쭤볼게...
#include "stdafx.h"
#include <iostream>
#include <string>
#include <list>
using namespace std;
class CList_Class
{
public :
CList_Class(void ){};
~CList_Class(void ){};
int ValueT;
};
struct insa
{
long birth;
string name;
};
int _tmain(int argc, _TCHAR* argv[])
{
list<CList_Class> *Value = new list<CList_Class>();
list<CList_Class>::iterator it;
CList_Class *newValue = new CList_Class();
newValue->ValueT = 1;
Value->push_back(const_cast<CList_Class &>(*newValue) );
printf("%d\n",Value[0]); << 하나는 여기에 값이 0 이 나오는데
for (list<CList_Class>::iterator it = Value->begin(); it != Value->end(); it++)
{
printf("%d\n",*it); 여기서는 정상적으로 나옵니다.
}
list<insa> *Tempvalue = new list<insa>();
insa *sfsf =new insa();
sfsf->name = "ddddd";
sfsf->birth=12323;
Tempvalue->push_back(const_cast<insa &>(*sfsf));
for (list<insa>::iterator it = Tempvalue->begin(); it != Tempvalue->end(); it++)
{
printf("%d\n",*it); 여기서는 정상적으로 나옵니다. 단 하나만 나오고 안나옵니다.
insa *Temp = (dynamic_cast<insa &>(*it)); //그래서 이렇게 써봤는데.. 에러가 납니다.
printf("%s\n",Temp->birth);
}
delete Value;
delete sfsf;
delete Tempvalue;
return 0;
}
혹시 아시는분 답변주시면 감사드리겠습니다.
|