X-Received: by 10.55.23.105 with SMTP id i102mr13217172qkh.55.1517800995720; Sun, 04 Feb 2018 19:23:15 -0800 (PST) X-Received: by 10.31.3.215 with SMTP id f84mr4311727vki.9.1517800995482; Sun, 04 Feb 2018 19:23:15 -0800 (PST) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!q21no449491qtn.1!news-out.google.com!u51ni134qtk.1!nntp.google.com!q21no449485qtn.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: gnu.g++.help Date: Sun, 4 Feb 2018 19:23:14 -0800 (PST) In-Reply-To: <877es0k780.fsf@LkoBDZeT.terraraq.uk> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.56.235.76; posting-account=SVVH0AoAAABplEQzMkIR3gU7a0gK8IuF NNTP-Posting-Host: 122.56.235.76 References: <877es0k780.fsf@LkoBDZeT.terraraq.uk> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4bf2cfb2-353e-4720-84e2-4fd1e2bd199e@googlegroups.com> Subject: Re: Trouble debugging some STL code From: "davin.pearson@gmail.com" Injection-Date: Mon, 05 Feb 2018 03:23:15 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 161 Xref: csiph.com gnu.g++.help:342 On Tuesday, January 30, 2018 at 4:36:16 AM UTC+13, Richard Kettlewell wrote= : > "davin.pearson" writes: >=20 > > The following code generates a linker error: > [...] >=20 > You=E2=80=99ve tried to explicitly instantiate a template, but got the sy= ntax > wrong. See > https://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html for > details. >=20 > --=20 > https://www.greenend.org.uk/rjk/ Thank you for your helpful posting. I've got another problem for you. Here is my offending file: #include #include #include #include #include #include #include #include "../../2006/libd/string.hh" class Writer { public: friend Writer& operator << (Writer& w, const std::string& str) { w << str.c_str(); return w; } Writer& operator << (const dmp::string& str) { *this << str.const_char_star(); return *this; } Writer& operator << (const char* s) { for (const char* ch =3D s; *ch !=3D 0; ++ch) { printf("%c",*ch); } return *this; } Writer& operator << (const int& i) { printf("%d",i); return *this; } Writer& operator << (char ch) { printf("%c",ch); return *this; } }; const char endl =3D '\n'; class File_Writer : public Writer { private: FILE* f; public: File_Writer(FILE* f) { this->f =3D f; } }; File_Writer cout(stdout); template Writer& operator << (Writer& w, const std::set& set) { typename std::set::const_iterator it =3D set.begin(); while (it !=3D set.end()) { w << *it << "\n"; it++; } return w; } template Writer& operator << (Writer& w, const std::set& set); int main() { std::set myset; myset.insert("eggplant"); myset.insert("xylophone"); myset.insert("apple"); myset.insert("carrot"); myset.insert("banana"); { std::set::iterator it =3D myset.find("banana"); if (it =3D=3D myset.end()) { cout << "Banana not found" << endl; //std::cout << endl << *it; // SEGV: //*it =3D "Fourth"; // NOT ALLOWED } else { cout << "Banana found\n"; cout << "it=3D" << *it << endl; } } { std::set::iterator it =3D myset.find("xbanana"); if (it =3D=3D myset.end()) { cout << "xbanana not found" << endl; //std::cout << endl << *it; // SEGV: //*it =3D "Fourth"; // NOT ALLOWED } else { cout << "xbanana found\n"; cout << "it=3D" << *it << endl; } } cout << "myset=3D" << myset << "\n"; return 0; } cd 2018/map/ && ./set6.exe Banana found xbanana not found myset=3Dapple banana carrot eggplant xylophone Here is the contents of the dmp::string class: http://davinpearson.com/binaries/string.hh With dmp::string in place of std::string it returns the following printout: cd 2018/map/ && ./set6.exe Banana not found xbanana not found myset=3Dapple banana carrot eggplant xylophone Why is it returning banana not found? (it is in the set).