Страница 1 из 1

Наследование

Добавлено: 23 окт 2010, 07:32
Lotles
Подскажите как добавить функции из другого класса, в данном случае Fraction

Код: Выделить всё

#include <stdafx.h>
#include <conio.h>
#include "Fraction.h"
using namespace std;

class FloatFraction : public Fraction {
public:
    double get_float() {
     return static_cast<double>(get_num())/get_den();}

    void set_float(double x);
};
int main() {
    FloatFraction fract1;  
    fract1.set_float(0.5);
    cout << "Value of 0.5 is " << fract1.get_float() << endl;
    fract1.set_float(0.6);
    cout << "Value of 0.6 is " << fract1.get_float() << endl;
    return 0;
}
void FloatFraction::set_float(double x) {
    int new_val = static_cast<int>(x * 100.0);
    set(new_val, 100);
}

Re: Наследование

Добавлено: 23 окт 2010, 16:19
BulldozerBSG
Куда добавить?

Re: Наследование

Добавлено: 25 окт 2010, 09:42
BBB
Они наследуются.