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