d02 ex02 operator < ok

This commit is contained in:
hugogogo
2022-02-15 00:31:59 +01:00
parent b08663e74e
commit c9a833bc00
6 changed files with 60 additions and 31 deletions

View File

@@ -53,18 +53,15 @@ int const Fixed::_max = -1U >> (_frac +1);
*/
Fixed::Fixed() : _value(0) {
std::cout << "Default constructor called" << '\n';
return;
}
Fixed::Fixed(Fixed const & src) {
std::cout << "Copy constructor called" << '\n';
*this = src;
return;
}
Fixed::~Fixed( void ) {
std::cout << "Destructor called" << '\n';
return;
}
@@ -73,8 +70,6 @@ Fixed::~Fixed( void ) {
*/
Fixed::Fixed(int integer) {
std::cout << "Int constructor called" << '\n';
if (integer < ~this->_max || integer > this->_max)
std::cout << "error: integer out of range" << '\n';
else
@@ -82,8 +77,6 @@ Fixed::Fixed(int integer) {
}
Fixed::Fixed(float const floater) {
std::cout << "Float constructor called" << '\n';
if (floater < ~this->_max || floater > this->_max)
std::cout << "error: float out of range" << '\n';
else
@@ -95,12 +88,33 @@ Fixed::Fixed(float const floater) {
*/
Fixed & Fixed::operator=( Fixed const & rhs ) {
std::cout << "Copy assignment operator called" << '\n';
if ( this != &rhs )
this->_value = rhs.getRawBits();
return *this;
}
/*
* other operators
*/
//Fixed Fixed::operator+( Fixed const & rhs ) const {
// return Fixed( this->toFloat() + rhs.toFloat() );
//}
bool Fixed::operator< (Fixed const & rhs) const {
return this->toFloat() > rhs.toFloat();
}
//Fixed operator> (Fixed const & rhs) const {
//}
//Fixed operator<=(Fixed const & rhs) const {
//}
//Fixed operator>=(Fixed const & rhs) const {
//}
//Fixed operator==(Fixed const & rhs) const {
//}
//Fixed operator!=(Fixed const & rhs) const {
//}
/*
* functions that returns _value
*/
@@ -125,8 +139,8 @@ float Fixed::toFloat( void ) const {
* took here : https://github.com/pgomez-a/42_CPP_Piscine/blob/master/cpp02/ex01/Fixed.cpp
*/
std::ostream & operator<<(std::ostream & out, Fixed const & fixed)
std::ostream & operator<<(std::ostream & o, Fixed const & rhs)
{
out << fixed.toFloat();
return (out);
o << rhs.toFloat();
return (o);
}