compiler bug

Artak Avetyan artak@softhome.net
Tue Jan 16 03:29:00 GMT 2001


Hi.
Recently came across with a problem. Compiler came crazy in using of
FRIEND function in class declared as
a TEMPLATE.
Here is a sample :
template < class
TYPE>
class Temp
{
public :
    Temp()
    {m_nData = 10 ;}
public :
    // Here I do not agree with
declaration (using of keyword TEMPLATE ),
because
    // " TYPE "  I already
declared in class. It must be -
    //
friend
TYPE Multiply(Temp<TYPE> temp, unsigned
long nLong);
    // But compiler wants so.
Whatever, the problem is not here !!!
    template
<TYPE> friend
TYPE Multiply(Temp<TYPE> temp, unsigned long nLong);
protected :
    TYPE    m_nData;
};
template < class
TYPE>
TYPE Multiply(Temp<TYPE> temp, unsigned
long nULong)
{
    temp.m_nData *= (TYPE)nULong;
    return
temp.m_nData;
}
int main( int
argc, char
*argv[ ], char
*envp[ ] )
{
    Temp< long >
temp;
    unsigned
long nULong = 0xFF ;
    // Note, here I get message,
that in function Multiply cannot access to
    // protected member Temp<long>::m_nData;
    long
nRes = Multiply(temp, nULong);    //
the result must be 2550
    return
( int )
nRes;
}
I use Pentium III - 550, 64 MB RAM, Linux Mandrake
7.0, Disk free space >= 2GB.
If I made mistakes, please inform me as soon as
possible, because it is very urgent for me.
By the way, I'll thank you very much if you tell
me (or when I can download) how to switch off warnings using #pragma, and
list of warning numbers.
With regards,
Artak.
P.S. Actually I found other bug as well, which
behaves absolutely similar as in MS Visual C++, it is connected with virtual
functions table. I'll send a sample next time (already reported to MS).



More information about the Gcc-bugs mailing list