Легенда:
новое сообщение
закрытая нитка
новое сообщение
в закрытой нитке
старое сообщение
|
- Напоминаю, что масса вопросов по функционированию форума снимается после прочтения его описания.
- Новичкам также крайне полезно ознакомиться с данным документом.
[C++ Bug] Bug report 25.07.01 03:08 Число просмотров: 827
Автор: Ван Мо Статус: Незарегистрированный пользователь
|
Па-руски говоря у тебя написано так:
#include <stdio.h>
void* operator new (size_t size, void *ptr)
{
return ptr;
}
class Parent
{
public:
virtual void PrintMsg() { printf("This function called from class Parent.\n"); }
};
class Child: public Parent
{
public:
virtual void PrintMsg() { printf("This function called from class Child.\n"); }
void Magic()
{
new (this) Parent;
printf("Leave Magic.\n");
}
};
int main()
{
Child child;
Child* pChild = &child;
Child& rChild = child;
child.PrintMsg();
pChild->PrintMsg();
rChild.PrintMsg();
printf("\n");
child.Magic();
printf("\n");
child.PrintMsg();
pChild->PrintMsg();
rChild.PrintMsg();
return 0;
}
---
В результате имеем
This function called from class Child.
This function called from class Child.
This function called from class Child.
Leave Magic.
This function called from class Child.
This function called from class Parent.
This function called from class Parent.
---
Теперь так же па-руски объясни что ты хотел сказать конструкцией new (this) Parent;
|
|
|