For Programmers: Free Programming Magazines  


Home > Archive > Visual Studio > September 2004 > Operator Overloading Causes "Debug Assertion Failed!" Error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Operator Overloading Causes "Debug Assertion Failed!" Error
Artist

2004-09-24, 3:59 am

I am trying to write operator overload code for a class used in matrix
multiplication. The relevant code is pasted is below. On return from the
multiply operator code I get the error:

Debug Assertion Failed!
Program: ...roj\Array Class.exe
File: dbgdel.cpp
Line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

My guess is I am not returning the resulting object of the multiplication
properly. If this is true what is the correct way to return the result? Or
what else could it be?

**** Code ****

cDicastArray<float> *Arr[3];
Arr[1] = new cDicastArray<float>();
Arr[2] = new cDicastArray<float>();

Arr[0] = &( *Arr[1] * *Arr[2] );

template<class T> cDicastArray<T> operator*(cDicastArray<T> left,
cDicastArray<T> right)
{ // Matrix multiply code omitted for clarity
cDicastArray<T> out( larger->getcDW(), outD ); // The output object.
// Matrix multiply code omitted for clarity
return out; // Debug Assertion Failed! error on this return
}

---
If you wish to respond to me directly remove the sj. in the domain name of
my email address. This is a spam jammer.


Artist

2004-09-25, 4:00 am

I have discovered the problem is that in the operator*() function the "out"
object's destructor is being called on return. There are dynamic arrays in
the cDicastArray class that are deleted in the destructor. That the
destructer is called is logical because the out variable goes out of scope
upon the return from operator*(). Does this mean a class for which a binary
operator is defined cannot have a destructor? How is a deleted object
supposed to be passed to the equation that called this overloaded operator?
The return of this object having local scope in the definition of the
operator*() was done according examples in chapter 11 of the "C++ Programing
Language, Special Edition," by Bjarne Stroustrup, who of all people should
know how to do this. How is this supposed to work?

"Artist" <artist@sj.speakeasy.net> wrote in message
news:Ys6dncKgjp8XBs7cRVn-ug@speakeasy.net...
>I am trying to write operator overload code for a class used in matrix
>multiplication. The relevant code is pasted is below. On return from the
>multiply operator code I get the error:
>
> Debug Assertion Failed!
> Program: ...roj\Array Class.exe
> File: dbgdel.cpp
> Line: 52
> Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
>
> My guess is I am not returning the resulting object of the multiplication
> properly. If this is true what is the correct way to return the result? Or
> what else could it be?
>
> **** Code ****
>
> cDicastArray<float> *Arr[3];
> Arr[1] = new cDicastArray<float>();
> Arr[2] = new cDicastArray<float>();
>
> Arr[0] = &( *Arr[1] * *Arr[2] );
>
> template<class T> cDicastArray<T> operator*(cDicastArray<T> left,
> cDicastArray<T> right)
> { // Matrix multiply code omitted for clarity
> cDicastArray<T> out( larger->getcDW(), outD ); // The output object.
> // Matrix multiply code omitted for clarity
> return out; // Debug Assertion Failed! error on this return
> }
>
> ---
> If you wish to respond to me directly remove the sj. in the domain name of
> my email address. This is a spam jammer.
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com