struct A ; // declare A: A is an incomplete type at this point
void foo( A* ptr ) // ptr is a pointer to an incomplete type at this point
{
// LLVM clang++: *** warning: deleting pointer to incomplete type 'A' may cause undefined behavior
// note: forward declaration of 'A' (line 3)
// GNU g++ : *** warning: possible problem detected in invocation of delete operator
// *** warning: 'ptr' has incomplete type
// note: forward declaration of 'struct A' (line 3)
// note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
// Microsoft cl: *** warning: deletion of pointer to incomplete type 'A'; no destructor called
// note: see declaration of 'A' (line 3)
delete ptr ;
}
struct A { /* ... */ }; // define A: A is a complete type at this point
void bar( A* ptr ) // // ptr is a pointer to a complete type at this point
{
delete ptr ; // this is fine
}
I can't use full declaration in header while including header with forward declaration not work.
At the moment, I have found solution: create function for delete in same file with structure and just call its from other file. Its should work.