Dictionary compilation problem (friend inline methods)

Hi,

I am testing a software based on ROOT with SLC5 and gcc 4.3.
I get a lot of errors within the Dictionary when I have “friend inline” methods (in a template context), such as

template<typename ScalarType>
class MonitorObjectScalar: public MonitorObject {

// <SNIP>

friend inline ScalarType Value(const MonitorObjectScalar<ScalarType>& rhs) { return(rhs.fVal); };

This produces the errors :

[code]CoreDict.cpp: In function ‘int G__CoreDict_147_0_3(G__value*, const char*, G__param*, int)’:
CoreDict.cpp:3581: error: no matching function for call to ‘Value(amore::core::MonitorObjectScalar&)’
CoreDict.cpp: In function ‘int G__CoreDict_147_0_16(G__value*, const char*, G__param*, int)’:
CoreDict.cpp:3691: error: no matching function for call to ‘Value(amore::core::MonitorObjectScalar&)’

It continues like that…[/code]

And the line 3581 of the Dictionary is

static int G__CoreDict_147_0_3(G__value* result7, G__CONST char* funcname, struct G__param* libp, int hash)
{
      G__letint(result7, 99, (long) amore::core::Value(*(amore::core::MonitorObjectScalar<char>*) libp->para[0].ref)); // line 3581 !!!
   return(1 || funcname || hash || result7 || libp) ;
}

I didn’t change anything in my code and it works fine with gcc 3.4. It does that for all the “friend inline” methods.

Do you have any idea why it doesn’t work ? or any clue on what I am doing wrong ?

Thanks in advance

Barth

Hi,

I think this is actually a C++ question :slight_smile:. If I remember correctly, gcc 4.3 (as opposed to gcc 3.4) is implementing correctly the fact that a ‘friend’ statement is not a declaration for the function. In you case this mean that if your line:friend inline ScalarType Value(const MonitorObjectScalar<ScalarType>& rhs) { return(rhs.fVal); }; is the only mention of the function ‘Value’ then, as far as the C++ compiler is concerned, it is not declared.

To solve this problem, you must add an explicit declaration of your function in the correct scope.

Cheers,
Philippe.

Ps. this rule is necessary because otherwise the actually ‘scope’ of the function is somewhat ambiguous.

Hi,

Thanks a lot for your reply, which makes a lot of sense. I will try what you suggest.

Cheers,