class MyLinkedList
{
int size_;
Node head;
void setVal(void *val, int type)
{
Node n;
n.value = val;
head.next->prev = &n;
n.next = head.next;
head.next = &n;
n.prev = &head;
n.type = type;
size_++;
}
MyLinkedList()
{
size_=0;
head.type = 0;
head.next = &head;
head.prev = &head;
}
void setValue(string value)
{
cout << value << endl;
setVal(&value,3);
}
void toConsFirst()
{
int *i;
double *d;
string *s;
switch(head.next->type)
{
case 3:
s = (string*)(head.next -> value);
cout << *s << endl;
return;
}
}
}
ケース 3 に問題があります: from "*s" はコンソールに文字列を出力しません。しかし、setValue() 文字列の「値」は問題ありません。ケース 3 では、"&value" の "value" と "s" の "*s" から seValue() を変更します。これは addr と同じです。