public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: onofre@ieav.cta.br To: gcc-gnats@gcc.gnu.org Subject: c++/5962: g++ compile an link Date: Thu, 14 Mar 2002 04:36:00 -0000 [thread overview] Message-ID: <20020314123221.2368.qmail@sources.redhat.com> (raw) >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 PTIuOwogIGI9My47CiAgCiAgQ29tcGxleDxmbG9hdD4gY2koYSxiKTsKICBDb21wbGV4PGZsb2F0 PiBjaihhLGIpOwogIAogIGlmKGNpPT1jaikKICAgIGNvdXQ8PCAiIHNhbWUgTnVtYmVycyAiPDxl bmRsOwogIGVsc2UKICAgIGNvdXQgPDwgIm51bWJlcnMgbm90IHRoZSBzYW1lIiA8PCBlbmRsOwog ICAKICAgIAogIGNvdXQ8PCBjaS5SZWFsKCkgPDwgIiArICIgPDwgY2kuSW1hZygpIDw8IGVuZGw7 ICAgCiAgfQo=
next reply other threads:[~2002-03-14 12:36 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-03-14 4:36 onofre [this message] 2002-03-29 12:21 mmitchel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020314123221.2368.qmail@sources.redhat.com \ --to=onofre@ieav.cta.br \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).