Here my third question ;-), but I'm actually new to c ++ template programming and operator overloading.
I am trying the following:
terminallog.hh
// snippet code class terminology {public: terminology (); Terminallog (int); Virtual ~ terminology (); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Const T & V); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Const std :: vector & lt; T & gt; & amp; v); Template & lt; Class T & gt; Terminology & amp; Operator & lt; & Lt; (Cost TV []); Terminology & amp; Operator & lt; & Lt; (Const char v []); // snap code}; // Snippid code template & lt; Class T & gt; Terminology and Terminology :: Operator & lt; & Lt; (Const T & V) {std :: cout & lt; & Lt; Std :: endl; This- & gt; letter of demand (); Std :: cout & lt; & Lt; V; Return * This; } Template & lt; Square T & gt; Terminology and Terminology :: Operator & lt; & Lt; (Const std :: vector & lt; T & gt; & amp; v) {for (unsigned int i = 0; i is trying to compile this code, it gives me a linker error:
G ++ src / Terminallog.cc inc / terminallog.hh Testmain.cpp -o test -Wall -Werror /tmp/ccifyOpr.o: function `Terminallog :: Operator & lt; & Lt; (Char const *) ': testmain.cpp :( text + 0x0): `Terminallog's many definitions :: operator & lt; & Lt; (Char const *) '/tmp/cccnEZlA.o:terminallog.cc:(.text+0x0): the first defined storage here 2: ld 1 exit status So I am currently backing my head against the wall, I am searching for a solution. But I can not find one in the wall ...
It would be nice if someone could show me my mistake
Thank you very much
ftiaronsem
this function
terminology and terminology :: operator & lt; & Lt; (Const four IV []) {std :: cout & lt; & Lt; Std :: endl; This- & gt; letter of demand (); Std :: cout & lt; & Lt; V; Return * This; } is not a template, but there is a regular member function. If you are included in the CPP file, you will see several definition errors. If you declare it to inline , then the compiler will allow several definitions and your error should be fixed. Inline terminology and terminology :: operator & lt; & Lt; (Const four V []) {
Comments
Post a Comment