d02 ex02 operator < ok
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user