I am using a simple struct guys, no classes, no inheritance.
A simple struct and it uses my new operator but the ATL delete
because the ATL delete operator matches the parameter
definition of my delete.
Printable View
I am using a simple struct guys, no classes, no inheritance.
A simple struct and it uses my new operator but the ATL delete
because the ATL delete operator matches the parameter
definition of my delete.
Please show the ATL overload and your specific overload. I think you need to call the operator delete with explicit syntax with the arguments.
my delete:
inline void operator delete(void* ptr)
{
free( ptr );
..
}
ATL definition my code is using:
void __cdecl operator delete(void* p)
{
#if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
_free_dbg(p, _NORMAL_BLOCK);
#else
free(p);
#endif
}
:eek:Quote:
Originally Posted by seany
You know, operator delete has class scope.
Which means that:
S1::operator delete has no conflict with S2::operator delete !Code:struct S1
{
void* operator new(size_t); // It declares S1::operator new
void operator delete(void*); // It declares S1::operator delete
};
struct S2
{
void* operator new(size_t); // It declares S2::operator new
void operator delete(void*); // It declares S2::operator delete
};
Please, show your code.
I am not sure and the class scope definition should have had been used but still try doing something like this:MyClass is the class for which the operator is overloaded. Again, I am not sure if this works or is a correct syntax but Comeau didn't have any problems. Regards.Code:MyClass::operator delete (p);
The implementation I have uses a macro such as when I declare a struct I do it like:
struct someObject
{
inline void* operator new(size_t sz){ ... } calls malloc
inline void operator delete(void* ptr){ ... } calls free
inline void* operator new[](size_t sz){ ... } calls malloc
inline void operator delete[](void* ptr){ ... } calls free
int x, y;
char a, b;
etc
};
This is an ATL issue, or mixing ATL with non-ATL code.
My new operator gets called, and I know the macro has
worked in a codebase with no ATL.
I do not think adding scope resolution operators to the inline definitions
of contained functions will make any difference. I know it works, just its now being caused by ATL. Why is my problem?
This btw, also only works because my overloaded uses malloc/delete just as the ATL code does. If it used anything else, my heap would be corrupted.
Did you try atleast rather than saying it would not make any difference :mad: ? I know it may not work but not for the reason that you wrote. Also, I am interested to know if it works because I am unable to reproduce the problem that you are facing and it may help me or interested others in knowing if this is a solution. Regards.Quote:
Originally Posted by seany
I tried the suggestion exterminator. I created a new ATL project with struct that has overridden new and delete. I tried both with scope resolution and without. Both worked fine. I expected this. The problem is that the ATL definitions in the sample project are not as comprehensive as the one's I am dealing with in a precompiled header I use. So.....
I'm going to check using the scope operator in the current project, its just going to take time.
seany.
If it works as expected then what is the problem? What do you mean by the following?
Regards.Quote:
Originally Posted by seany
It worked for the sample project, it does not work for the one I am working with - thats what I meant to say in the last post.
So I changed the code to use the scope operator and it has worked for me in my own workspace.
This is good. Thanks.
Okay.. so that is a good news.. :) Thank you for confirming... :)Quote:
Originally Posted by seany
Mhh.. I would like to know the reason of that strange "bug"...Quote:
Originally Posted by seany
Are you sure you delete your object with a pointer to the structure (and not void*, char*, or any other pointer)!
Code:struct S *s=new S;
delete (void*)s; // undefined behaviour