#include <iostream>
class Rectangle
{
public :
Rectangle( double w = 0 , double h = 0 , double r = 0 ) : width( w) , height( h) , radius( r)
{ }
double width;
double height;
double radius;
} ;
namespace traits
{
template < typename P>
struct operations
{
static void display( Rectangle const & , std:: ostream & ) ;
static double area( Rectangle const & ) ;
} ;
template < typename P, int N>
struct access { } ;
}
namespace traits
{
template < int N>
struct access< Rectangle, N>
{
static double get( Rectangle const & ) ;
} ;
}
namespace traits
{
template <>
struct access< Rectangle, 0 >
{
static double get( Rectangle const & rect)
{
return rect.width ;
}
} ;
template <>
struct access< Rectangle, 1 >
{
static double get( Rectangle const & rect)
{
return rect.height ;
}
} ;
}
namespace traits
{
template <>
struct operations< Rectangle>
{
static void display( Rectangle const & rect, std:: ostream & os)
{
os << "Width of rectangle: " << rect.width << std:: endl ;
os << "Height of rectangle: " << rect.height << std:: endl ;
os << "Area of rectangle: " << area( rect) << std:: endl ;
}
static double area( Rectangle const & rect)
{
double width = access< Rectangle, 0 > :: template get< 0 > ( rect) ;
double height = access< Rectangle, 1 > :: template get< 1 > ( rect) ;
return width * height;
}
} ;
}
template < int N, typename P>
static inline double get( P const & p)
{
return traits:: access < P, N> :: get ( p) ;
}
template < typename P>
static inline void display( P const & p)
{
traits:: operations < P> :: display ( p, std:: cout ) ;
}
template < typename P>
static inline double area( P const & p)
{
return traits:: operations < P> :: area ( p) ;
}
/*ostream & operator<<(ostream & out, Shape const& s)
{
s.display(out);
return out;
}*/
int main( )
{
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgUmVjdGFuZ2xlCnsKICAgICBwdWJsaWM6CiAgICAgUmVjdGFuZ2xlKGRvdWJsZSB3ID0gMCwgZG91YmxlIGggPSAwLCBkb3VibGUgciA9IDApIDogd2lkdGgodyksIGhlaWdodChoKSwgcmFkaXVzKHIpCiAgICAge30KCiAgICAgZG91YmxlIHdpZHRoOwogICAgIGRvdWJsZSBoZWlnaHQ7CiAgICAgZG91YmxlIHJhZGl1czsKfTsKCm5hb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0aWMgaW5saW5lIGRvdWJsZSBhcmVhKFAgY29uc3QgJnApCnsKICAgIHJldHVybiB0cmFpdHM6Om9wZXJhdGlvbnM8UD46OmFyZWEocCk7Cn0KCi8qb3N0cmVhbSAmIG9wZXJhdG9yPDwob3N0cmVhbSAmIG91dCwgU2hhcGUgY29uc3QmIHMpCnsKICAgICAgcy5kaXNwbGF5KG91dCk7CiAgICAgIHJldHVybiBvdXQ7Cn0qLwoKCmludCBtYWluKCkKewogICAgCn0=
compilation info
prog.cpp: In static member function ‘static double traits::operations<Rectangle>::area(const Rectangle&)’:
prog.cpp:70:52: error: ‘template’ (as a disambiguator) is only allowed within templates
prog.cpp:70:72: error: no match for ‘operator>’ in ‘false > rect’
prog.cpp:70:72: warning: comparisons like ‘X<=Y<=Z’ do not have their mathematical meaning [-Wparentheses]
prog.cpp:71:52: error: ‘template’ (as a disambiguator) is only allowed within templates
prog.cpp:71:65: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
prog.cpp:71:72: error: no match for ‘operator>’ in ‘(traits::access<Rectangle, 1>::get == 0u) > rect’
prog.cpp:71:72: warning: comparisons like ‘X<=Y<=Z’ do not have their mathematical meaning [-Wparentheses]
stdout