Hello all,
I want to delete a 2 level derived class with a function and putting its handle to null. A piece of code will be helpfull:
ref class bob
{
};
ref class bill : public bob
{
};
ref class jack : public bill
{
};
void DeleteX( bob ^% x )
{
if( x != nullptr )
{
delete x;
x = nullptr;
}
}
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
bill^ one = gcnew jack();
DeleteX(one);
System::Diagnostics::Trace::Assert(one == nullptr); //Failed
return 0;
}
If I use the same type for my declaration and for my function argument, it works. But I want to use the middle type for my declaration and the upper type for the function argument. How can I do this please ?
This is the solution I finally use:
template<class T>
void DeleteX( T ^% x )
{
if( x != nullptr )
{
delete x;
x = nullptr;
}
}