Re: VC8 Compiler bizarreness

Tech-Archive recommends: Fix windows errors by optimizing your registry



Alex Blekhman wrote:
"Murrgon" wrote:
I think that the culprit is `GTL::TSmartPtr<TYPE>' template.
It does define operator!=(), but the classes it's suggesting as the TYPE
don't.

The non relevant classes are te quirk of Koenig lookup that compiler tries to perform. It founds a lot of other `operator !=' in different namespaces however fails to match the arguments. The real error is with TSmartPtr. See comments inline.

[...]
TBool operator!=(TYPE* ptr)
{
return(m_pRefCountObject != ptr);
}

The above function must be const. Compilation fails because compiler cannot find appropriate const `operator !=' function for the statement "kObject != ptr".

friend INL TBool operator!=(TYPE* ptr, const TSmartPtr<TYPE>& kObject)
{
return(kObject != ptr);
}

As you can see, global `operatpr !=' accepts kObject parameter as constant reference. Compiler cannot call non-constant function on this reference in return statement. So, the fix is:

TBool operator!=(const TYPE* ptr) const
{
return(m_pRefCountObject != ptr);
}

I added another `const' qualifier for `ptr' parameter, so the operator is more generous about its input. Also, you should fix other member functions and operators of `TSmartPtr' class, so if a function does not change the object it have to be qualified as const. Global operator should accept const values, too.

Well, I went through and modified all of the operators to be const
along with their parameters, including the global ones, but that
didn't change anything. I still get the same abiguity error.

Good suggestion though :)

Murrgon
.



Relevant Pages

  • Re: VC8 Compiler bizarreness
    ... The non relevant classes are te quirk of Koenig lookup that ... compiler tries to perform. ... TBool operator!=(TYPE* ptr) ... The above function must be const. ...
    (microsoft.public.vc.language)
  • Re: assigning const char* to char*
    ... char* pS1 = s1; ... I assign the two const ptrs to some non-const ptrs to ... I thought I was doing the standard thing for ptr arithmetic. ... I mean that the compiler won't ...
    (comp.lang.c)
  • Re: sprintf leading up to bus error (signal 10)
    ... I don't know what exactly you're doing but this pointer cast makes me suspect that this is the case. ... value returned by malloc to the pointer you want to point to it. ... you are effectively telling the compiler you want space for N of the things ptr points to. ...
    (comp.lang.c)
  • Re: Smart pointers and subclasses
    ... when all references are deleted, ... I'm now looking at CAutoPtr and CAutoPtrArray as options. ... allow copying from other types of Ptr. ... T* getconst ...
    (microsoft.public.vc.mfc)
  • Re: const variables
    ... The pointed-to int cannot be changed through ptr, ... Is it the C compiler that would give compile time error while trying to ... the behavior depends on what ptr and tmp point ... While freeing the memory, the compiler generated warning. ...
    (comp.lang.c)