fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. template< typename T >
  8. class Rect{
  9. protected:
  10. T width, height;
  11. public:
  12. Rect(T a, T b){
  13. width = a;
  14. height = b;
  15. }
  16. template< typename U >
  17. Rect(Rect<U> const &r){
  18. width = r.width;
  19. height = r.height;
  20. }
  21. int area(){
  22. return width*height;
  23. }
  24.  
  25. template <typename U> friend class Rect;
  26. };
  27.  
  28. int main(){
  29. Rect<int> a(3,4);
  30. Rect<float> b(a);
  31. cout<<b.area()<<endl;
  32. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
12