Newsgroup: it.comp.lang.c++
Titolo: overloading >> with template classes and gcc

bug nel tuo compilatore ...
#include <fstream>
#include "_line_pricing.h"
#include "_line_pricing.cc"
using namespace std;
int main()
{
 _line_pricing< int > x_line( 40000, 50000, 40, 25 );
 ifstream in_file( "pricing" );
 in_file >> x_line;  // cin >> x_line is ok
   return 0;
}
   /* abstract class of pricing representation */
   class _a_pricing {
     public:
      /* it displays the pricing traits */
      virtual void display() const = 0;
    };
   /* class of pricing representation */
   template< class currency >
   class _line_pricing : public _a_pricing {
      /* extraction poerator */
      friend ostream& operator << ( ostream &os, const _line_pricing<
currency > &pricing );
      /* insertion poerator */
      friend istream& operator >> ( istream &is, _line_pricing< currency >
&pricing );
     public:
      /* constructors */
      _line_pricing( currency advance = currency(), currency price =
currency(), int child_discount = 0, int teen_discount = 0 );
      /* it displays the pricing traits */
      void display() const;
     private:
      /* pricing */
      currency _price;
      /* advance's representation */
      currency _advance;
      /*child's discount representation  */
      int _child_discount;
      /*teen's discount representation  */
      int _teen_discount;
    };
   /* insertion operator */
   template< class currency >
   ostream&
   operator << ( ostream &os, const _line_pricing< currency > &pricing )
   {
    os  << pricing._price
     << " "
     << pricing._advance
     << " "
     << pricing._child_discount
     << " "
     << pricing._teen_discount
     << endl;
    return os;
   }
   /* extraction operator */
   template< class currency >
   istream&
   operator >> ( istream &is, _line_pricing< currency > &pricing )
   {
    is  >> pricing._price
     >> pricing._advance
     >> pricing._child_discount
     >> pricing._teen_discount;
    return is;
   }
   /* constructor */
   template< class currency >
   _line_pricing< currency >::_line_pricing( currency advance, currency
price, int child_discount, int teen_discount ) :
   _advance( advance ),
   _price( price ),
   _child_discount( child_discount ),
   _teen_discount( teen_discount )
   {
   }
   /* it displays the pricing traits */
   template< class currency >
   void
   _line_pricing< currency >::display() const
   {
    cout  << "price per person is: "
      << _price
      << endl
      << "the advance is : "
      << _advance
      << endl;
   }

 undefined behaviour in void main.
"undefined behaviour" significa che il compilatore puo` fare quello
che vuole, e cosi` pure il programma che esso genera, e chi ha
scritto il programma non puo` che rispettare il proverbio "chi e`
causa del suo mal, pianga se` stesso".
Fra le piu` frequenti cause di undefined behaviour (che in un certo
senso e` la classe di errori piu` orrenda che un programma possa
contenere, in quanto non si puo` contare su nessuna diagnostica,
e neppure su errori ripetibili/diagnosticabili) e` la disastrosa prassi
di dichiarare main come void, mentre DEVE, a Standard, essere
dichiarato come int.  La responsabilita` di questo e` certo in buona
parte sugli autori di libri, reprensibili e da condannare, che usano
"void main" (dimostrando di non conoscere ne` il C, ne` il C++).
Alex