Переосмыслить приведение для указателя указателяC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Переосмыслить приведение для указателя указателя

Сообщение Anonymous »


I have two classes a class and a class (inheriting from the class) I would like to know if it is possible to cast/transform a to a

Код: Выделить всё

Parent**
with

Код: Выделить всё

reinterpret_cast
or something else?
Or such thing is not possible
Below is a minimal example. I am wondering is that code correct or to a

Код: Выделить всё

Parent**
"transformation" is not correct and should not be attempted?
NB: my question is on the conversion of the pointer of pointer. I.e. is this line correct ?

Код: Выделить всё

Parent** ptrToChildPtr = reinterpret_cast(&childPtr);
I know that the pointer deletion could be done in a much simpler way. I just want to show here the conversion I want to perform if such conversion is possible.
Many thanks in advance

Код: Выделить всё

#include 
#include 

class Parent {
public:
Parent() {}
virtual ~Parent() {
std::cout 

Источник: [url]https://stackoverflow.com/questions/78131924/reinterpret-cast-for-pointer-of-pointer[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»