cpp/CPP07/ex00/main.cpp
2024-12-04 17:29:31 +01:00

52 lines
1.7 KiB
C++

#include "whatever.hpp"
class Awesome
{
public:
Awesome(void) : _n(0) {}
Awesome( int n ) : _n( n ) {}
Awesome & operator= (Awesome & a) { _n = a._n; return *this; }
bool operator==( Awesome const & rhs ) const { return (this->_n == rhs._n); }
bool operator!=( Awesome const & rhs ) const{ return (this->_n != rhs._n); }
bool operator>( Awesome const & rhs ) const { return (this->_n > rhs._n); }
bool operator<( Awesome const & rhs ) const { return (this->_n < rhs._n); }
bool operator>=( Awesome const & rhs ) const { return (this->_n >= rhs._n); }
bool operator<=( Awesome const & rhs ) const { return (this->_n <= rhs._n); }
int get_n() const { return _n; }
private:
int _n;
};
std::ostream & operator<<(std::ostream & o, const Awesome &a) { o << a.get_n(); return o; }
int main(void)
{
std::cout << "\n---Test0---\n" << std::endl;
{
int a = 2;
int b = 3;
swap( a, b );
std::cout << "a = " << a << ", b = " << b << std::endl;
std::cout << "min( a, b ) = " << min( a, b ) << std::endl;
std::cout << "max( a, b ) = " << max( a, b ) << std::endl;
std::string c = "chaine1";
std::string d = "chaine2";
swap(c, d);
std::cout << "c = " << c << ", d = " << d << std::endl;
std::cout << "min( c, d ) = " << min( c, d ) << std::endl;
std::cout << "max( c, d ) = " << max( c, d ) << std::endl;
}
std::cout << "\n---Test1---\n" << std::endl;
{
Awesome a(2), b(4);
std::cout << "a: " << a << " b: " << b << std::endl;
swap(a, b);
std::cout << "a: " << a << " b: " << b << std::endl;
std::cout << "max: " << max(a, b) << std::endl;
std::cout << "min: " << min(a, b) << std::endl;
}
std::cout << "\n---EndTest---\n" << std::endl;
return (0);
}