M
mathieu
Hi there,
Is the following legal (*). I am reading:
http://www.parashift.com/c++-faq-lite/references.html#faq-8.6
But I am not sure I understand if in my case I should prefer pointer
over reference since new will throw and I will never dereference a
NULL pointer.
Thanks
(*)
struct A
{
virtual A& clone() { return *new A; }
};
struct B : public A
{
B& clone() { return *new B; }
};
int main()
{
A a;
A ©a = a.clone();
A * ptra = dynamic_cast<A*>(©a);
delete ptra;
B b;
A ©b = b.clone();
B * ptrb = dynamic_cast<B*>(©b);
delete ptrb;
return 0;
}
Is the following legal (*). I am reading:
http://www.parashift.com/c++-faq-lite/references.html#faq-8.6
But I am not sure I understand if in my case I should prefer pointer
over reference since new will throw and I will never dereference a
NULL pointer.
Thanks
(*)
struct A
{
virtual A& clone() { return *new A; }
};
struct B : public A
{
B& clone() { return *new B; }
};
int main()
{
A a;
A ©a = a.clone();
A * ptra = dynamic_cast<A*>(©a);
delete ptra;
B b;
A ©b = b.clone();
B * ptrb = dynamic_cast<B*>(©b);
delete ptrb;
return 0;
}