This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/5962: g++ compile an link
- From: onofre at ieav dot cta dot br
- To: gcc-gnats at gcc dot gnu dot org
- Date: 14 Mar 2002 12:32:21 -0000
- Subject: c++/5962: g++ compile an link
- Reply-to: onofre at ieav dot cta dot br
>Number: 5962
>Category: c++
>Synopsis: g++ compile an link
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Mar 14 04:36:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: onofre@ieav.cta.br
>Release: gcc version 3.0.4
>Organization:
>Environment:
conectiva linux
2.2.17-14cl #1 qui nov 2 00:24:54 EST 2000 i686
and mandrake 8.1 2.4.8
>Description:
when I try to compile the code that use template and friend
function the link show-me a message
g++ -o tcomplex tComplex.cc
tComplex.cc:15: warning: friend declaration `bool operator==(const Complex<T>&,
const Complex<T>&)' declares a non-template function
tComplex.cc:15: warning: (if this is not what you intended, make sure the
function template has already been declared and add <> after the function
name here) -Wno-non-template-friend disables this warning.
IMPORTANTE PARTE
/tmp/ccxZWYam.o: In function `main':
/tmp/ccxZWYam.o(.text+0x4d): undefined reference to `operator==(Complex<float> const&, Complex<float> const&)'
collect2: ld returned 1 exit status
>How-To-Repeat:
#include <iostream.h>
template <class T>
class Complex
{
public:
T a,b;
Complex(T ,T);
T Real();
T Imag();
friend bool operator==(const Complex <T> &,const Complex<T> &);
};
template <class T>
Complex<T>::Complex(T x,T y)
{
a = x;
b = y;
}
template <class T>
T Complex<T>::Real()
{
return a;
}
template <class T>
T Complex<T>::Imag()
{
return b;
}
template <class T>
bool operator ==(const Complex<T> &Ca,const Complex<T> &Cb)
{
if (Ca.a == Cb.a && Ca.b==Cb.b)
return true;
else
return false;
}
int main(int argc, char **argv)
{
float a,b;
a=2.;
b=3.;
Complex<float> ci(a,b);
Complex<float> cj(a,b);
if(ci==cj)
cout<< " same Numbers "<<endl;
else
cout << "numbers not the same" << endl;
cout<< ci.Real() << " + " << ci.Imag() << endl;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="tComplex.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="tComplex.cc"
I2luY2x1ZGUgPGlvc3RyZWFtLmg+Ci8vI2luY2x1ZGUgIkNvbXBsZXguaCIKCnRlbXBsYXRlIDxj
bGFzcyBUPiAKICAgY2xhc3MgQ29tcGxleAp7CiAgcHVibGljOgogIAogIFQgYSxiOwogIAogIENv
bXBsZXgoVCAsVCk7CiAgVCBSZWFsKCk7CiAgVCBJbWFnKCk7CiAgCiAgZnJpZW5kIGJvb2wgb3Bl
cmF0b3I9PShjb25zdCBDb21wbGV4IDxUPiAmLGNvbnN0IENvbXBsZXg8VD4gJik7CiAKIAoKICAK
fTsKdGVtcGxhdGUgPGNsYXNzIFQ+CkNvbXBsZXg8VD46OkNvbXBsZXgoVCB4LFQgeSkKeyAKICBh
ID0geDsKICBiID0geTsKICB9Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4gIApUIENvbXBsZXg8VD46OlJl
YWwoKQogIHsgCiAgICAgcmV0dXJuIGE7CiAgICAgfQoKCnRlbXBsYXRlIDxjbGFzcyBUPiAgICAg
IApUIENvbXBsZXg8VD46OkltYWcoKQogIHsgCiAgICAgcmV0dXJuIGI7CiAgICAgfSAgICAgCgoK
dGVtcGxhdGUgPGNsYXNzIFQ+CiBib29sIG9wZXJhdG9yID09KGNvbnN0IENvbXBsZXg8VD4gJkNh
LGNvbnN0IENvbXBsZXg8VD4gJkNiKQoKICB7CiAgICBpZiAoQ2EuYSA9PSBDYi5hICYmIENhLmI9
PUNiLmIpCiAgICAgIHJldHVybiB0cnVlOwogICAgZWxzZSAKICAgICAgcmV0dXJuIGZhbHNlOwp9
CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqKmFyZ3YpCnsKICAgIAogIGZsb2F0IGEsYjsKICBh
PT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