This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with function template specialization


On Thu, 30 Dec 2004 23:15:18 +0100 (CET), Patrick Percot <ppercot@free.fr> wrote

> On Thu, 30 Dec 2004 11:47:19 -0500, Christian Convey <conveycj@npt.nuwc.navy.mil> wrote
> 
> > Hello,
> 
> Hi,
> 
> > 
> > I'm trying to write a small library of function templates, all named 
> > "toString", that will produce a string rendition of various data types.
> > 
> > My problem is that when I try to create a specialized version of the 
> > toString() function for a particular data type, I get an error:
> > 
> 
> Don't you think  that operator overloading is a  better and more elegant
> solution ?
> 

Mmh, and I forgot to remove the template :

#include <iostream>
#include <sstream>
#include <vector>
#include <string>

using namespace std;

class Foo {
private:
  int x;
  int y;
public:
  Foo(int xv, int yv)
    : x(xv)
    , y(yv) {};
  friend ostream& operator<< (ostream& os, const Foo& f);
};


ostream& operator<< (ostream& os, const Foo& f) {
  os << "(" << &f << ") = Foo(" << f.x << ", " << f.y << ")";
}


int main() {
  Foo f(1,2);
  cout << f << endl;
}


[..Zappé 50 lignes et 918 caractères..]

À+
PP
-- 
NE MANGEZ PAS DE FOIE GRAS : http://www.stopgavage.com

Groupe Morbihannais d'Utilisateurs de Logiciels Libres http://www.tuxbihan.org
GPG fingerprint = 1A4F E154 3D2C A20E E4CA  A543 7951 C5C2 E44A A0B5

Patrick Percot.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]