Home › Forums › C Programming › Errors in Program › Reply To: Errors in Program
August 13, 2007 at 10:11 am
#3250
S.Thananchayan
Participant
Ewwww thats got problems try this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream><br /> template<class B1, class B2><br /> class MyBook {<br /> B1 book1;<br /> B2 book2;<br /> public:<br /> MyBook(B1 b1, B2 b2) : book1(b1), book2(b2)<br /> { }<br /> template</class><class B3, class B4><br /> friend std::ostream& operator<<(std::ostream& os,<br /> const MyBook<B3, B4>&);<br /> };<br /> template</class><class B1, class B2><br /> std::ostream& operator<<(std::ostream& os,<br /> const MyBook<B1, B2>& bb)<br /> {<br /> std::cout<<"My book has " << bb.book1 << ' ' << "pages" << std::endl;<br /> std::cout<<"I just tore out " << bb.book1 - bb.book2 << ' ' << "pages" << std::endl;<br /> std::cout<<"My book now has " << bb.book2 << ' ' << "pages" << std::endl;<br /> return os;<br /> }<br /> int main()<br /> {<br /> int a = 970;<br /> int b = 965;<br /> MyBook<int,double> my_twothings(a, b);<br /> std::cout << my_twothings << std::endl;<br /> return 0;<br /> }</class></iostream> |