Hej! Mam problem z przeładowaniem operatora. W main mam takie coś:
#include "Money.h"
#include <iostream>
int Currency::USD = 1;
int Currency::PLN = 0;
int main() {
using namespace std;
Money x(1034179*Currency::USD); // w jakis sposob konstruktor z USD musi odroznic PLN
cout << Currency::type(x) << endl;
const Money y(5633*Currency::PLN);
cout << Currency::type(y) << endl;
Zadeklarowałam powyższe funkcje tak:
class Currency{
public:
static int USD;
static int PLN;
static char * type(const Money & obj);
};
void operator*(const Money & obj, int typ_waluty) {
obj.typ_waluty = typ_waluty;
definicja funkcji type::
char * Currency::type(const Money & obj) {
//cout<<obj.typ_waluty<<endl;
if(obj.typ_waluty == 1) {
return "USD";
} else return "PLN";
}
Niestety w wyniku program nie działa poprawnie, a operator* nie wykonuje się.