Re: VC8 Compiler bizarreness



"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.

HTH
Alex


.



Relevant Pages

  • Re: VC8 Compiler bizarreness
    ... but the classes it's suggesting as the TYPE ... 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: Writing single bits to a file
    ... The 'const' keyword provides the same kind of benefit that prototypes ... enabling the compiler to warn you if it detects the fact that you ... I had not gone and more correctly fixed up the precedence heirarchy (unary ... I like to implement scripting languages for breakfast ...
    (comp.lang.c)
  • Re: const
    ... > const modifiers, ... willing to remove the const'ness with a cast, ... I don't know how good a cross-file compiler could be - it would have to be ... it's a guarantee by the programmer. ...
    (comp.programming)
  • Re: Index a #define string
    ... In this case, i wouldn't use an array myself but a const char * const, but ... should one make it of static storage? ... If they were on the stack, where do you think their values ... You mean that the compiler optimises it out. ...
    (comp.lang.cpp)