Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Working on an old project, I found some code that appears to be ASSERTing a class reference.

class classA
{
public:
...
classB myClassB;
};

classA::classA
{
ASSERT (myClassB);
}

I can't even get this syntax to compile in a brand new C++ project (VS2012).

We do have our own definition of ASSERT which goes

C#
#define ASSERT(statement)                                       \
    if (!(statement))                                           \
    {                                                           \
        logAssertion (TEXT(#statement), __FILE__, __LINE__);    \
    }


(The one in the MS includes (afh.h) looks like this)
#define ASSERT(f)          DEBUG_ONLY((void) ((f) || !::AfxAssertFailedLine(THIS_FILE, __LINE__) || (AfxDebugBreak(), 0)))




classB is derived from CWnd, it seems to pass the ASSERT when its HWND is non NULL (this is just a guess, though that is the intention of the ASSERT in the old code). Is there an operator in the class that could be responsible for this sort of validity check?


Edit ---


In my old code .... if I assert on a CString it compiles, if I ASSERT on a primitive class like ClassA above it fails to compile on
error C2675: unary '!' : 'classA' does not define this operator or a conversion to a type acceptable to the predefined operator
Posted
Updated 18-Feb-15 2:49am
v2
Comments
nv3 18-Feb-15 10:24am    
The CString contains an automatic cast to LPTSTR which then can be tested by the ASSERT. Please check if your old ClassA contains an override of

xxx* operator()()

That would explain why the ASSERT did work in you old code.
Sergey Alexandrovich Kryukov 18-Feb-15 12:07pm    
What is "class reference"? :-)
—SA
Mike Nordell 14-Mar-15 2:53am    
I suspect "myClassB" at some point in time was a pointer, making the assert make sense. Actually, anything else makes no sense to me.

Just remove that (useless) "assert" and get on to finding the actual bugs. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900