From -3888276172845511387 X-Google-Thread: f78e5,adfa3ea7cd149e36,start X-Google-Attributes: gidf78e5,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.cs.univ-paris8.fr!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull From: lgalfaso@gmail.com (Lucas Galfaso) Newsgroups: comp.std.c++ Subject: Specialization of a template cast. Date: Mon, 25 Apr 2005 01:25:20 GMT Lines: 65 Sender: mail2news@demon.net Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++) Message-ID: NNTP-Posting-Host: news.news.demon.net Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.demon.co.uk 1114392327 1411 158.152.254.254 (25 Apr 2005 01:25:27 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Mon, 25 Apr 2005 01:25:27 +0000 (UTC) X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=s4Cyu/JNxZfn8oKKYVl22otrtoIlOnrOgLYTLy+0hHIYLy4YHzVX6FgPJGtzuKjTaOhgQh7ikUQ/S0kK7VlsA9rgfzOFIKgaS4DL3iOiAOZFfdsPI7GOxU+QHZHJEMNO9KY8/Xp9ksV4C047VqlmCE1V/E2O55joqIdoaYvLR4c= X-MIME-Autoconverted: from quoted-printable to 8bit by mailman.ucar.edu id j3OHfVKE014988 X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU Content-Disposition: inline X-Reply-To: Lucas Galfaso X-Path: comp-std-cpp-robomod!not-for-mail X-Received: (from fjh@localhost) by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j3P1PKoQ019156; Mon, 25 Apr 2005 11:25:20 +1000 (EST) X-Delivered-To: std-c++@ucar.edu X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Newsgroups: comp.std.c++ Xref: g2news1.google.com comp.std.c++:4584 Hi, From the standard, it is not clear how you should (a) create a specialization from a template cast and (b) use a specific specialization on a cast, ie (A) #include using namespace std; class Foo { int m_foo; public: Foo () : m_foo(0) {} template operator _Ty() const { cout << "This is a specialization on the type " << typeid(_Ty).name() << endl; return (_Ty) m_foo; } // How you write a specialization of the template cast above? // template <> operator int() const {return m_foo;} ? // template <> operator int() const {return m_foo;}? // template <> operator int() const {return m_foo;}? }; (B) #include using namespace std; class Foo { int m_foo; public: Foo () : m_foo(0) {} template operator _Ty() const { cout << "This is a specialization on the type " << typeid(_Ty).name() << endl; return (_Ty) m_foo; } operator int() const { cout << "This is a standard cast to int" << endl; return m_foo; } }; int main() { Foo foo; cout << (int)foo; // this will call the non-template version of the cast, how you call the template version for the type int? return 0; } Thanks, Lucas Galfaso --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]