Podstawiłem do tego kodu mój ulamek i oto odpowiedz linkera:
Kopiuj
[ILINK32 Error] Error: Unresolved external 'ulamek::~ulamek()' referenced from C:\DOCUMENTS AND SETTINGS\MASTODONT\MOJE DOKUMENTY\RAD STUDIO\PROJECTS\DEBUG\FILE2.OBJ
[ILINK32 Error] Error: Unresolved external 'operator >>(std::basic_istream<char, std::char_traits<char> >&, ulamek&)' referenced from C:\DOCUMENTS AND SETTINGS\MASTODONT\MOJE DOKUMENTY\RAD STUDIO\PROJECTS\DEBUG\FILE2.OBJ
[ILINK32 Error] Error: Unresolved external 'ulamek::ulamek(int, int)' referenced from C:\DOCUMENTS AND SETTINGS\MASTODONT\MOJE DOKUMENTY\RAD STUDIO\PROJECTS\DEBUG\FILE2.OBJ
[ILINK32 Error] Error: Unresolved external 'operator <<(std::basic_ostream<char, std::char_traits<char> >&, const ulamek&)' referenced from C:\DOCUMENTS AND SETTINGS\MASTODONT\MOJE DOKUMENTY\RAD STUDIO\PROJECTS\DEBUG\FILE2.OBJ
a to kod ulamka. Dodam że sam ulamek mi działa i nie potrafię rozgryźć czemu przy operacjach na plikach się sypie.
Kopiuj
#include<math.h>
#include<iostream.h>
class ulamek{
private:
int l,m;
friend ostream& operator<< (ostream&, const ulamek&);
friend istream& operator>> (istream&, ulamek&);
public:
ulamek(int = 0,int = 1);
ulamek(const ulamek&);
~ulamek();
void set(int,int);
float oblicz();
ulamek operator+(const ulamek &);
ulamek operator-(const ulamek &);
ulamek operator*(const ulamek &);
ulamek operator/(const ulamek &);
ulamek operator=(const ulamek &);
void operator+=(const ulamek &);
void operator-=(const ulamek &);
void operator*=(const ulamek &);
void operator/=(const ulamek &);
ulamek operator()(int, int);
int operator==(const ulamek &);
operator float(){
return (float)l/m;
}
};
#include "ulamek.h
code>`#include "ulamek.h"
ulamek::ulamek(int a, int b):l(a),m(b){}
ulamek::~ulamek(){}
ulamek::ulamek(const ulamek &other){
l=other.l;
m=other.m;
}
void ulamek::set(int a, int b){
l = a;
m = b;
}
float ulamek::oblicz(){
if (m==0) {
cout<<"Mianownik rowny (0) - wyjscie z programu"<<endl;
system("pause");
exit(1);
}
float tmp = (float)l/(float)m;
return tmp;
}
ulamek ulamek::operator+(const ulamek &other){
l*=other.m;
int tmp = other.lm;
m=other.m;
l+=tmp;
return (this);
}
ulamek ulamek::operator-(const ulamek &other){
l=other.m;
int tmp = other.lm;
m=other.m;
l-=tmp;
return (this);
}
ulamek ulamek::operator(const ulamek &other){
l*=other.l;
m*=other.m;
return (this);
}
ulamek ulamek::operator/(const ulamek &other){
l=other.m;
m*=other.l;
return (this);
}
ulamek ulamek::operator=(const ulamek &other){
l=other.l;
m=other.m;
return (this);
}
void ulamek::operator+=(const ulamek &other){
l=other.m;
int tmp = other.lm;
m*=other.m;
l+=tmp;
}
void ulamek::operator-=(const ulamek &other){
l*=other.m;
int tmp = other.lm;
m=other.m;
l-=tmp;
}
void ulamek::operator*=(const ulamek &other){
l*=other.l;
m*=other.m;
}
void ulamek::operator/=(const ulamek &other){
l*=other.m;
m*=other.l;
}
ulamek ulamek::operator()(int a, int b){
l=a;
m=b;
return *this;
}
int ulamek::operator==(const ulamek &other){
if ((l/m)==(other.l/other.m)) {
return 1;
}
else return 0;
}
ostream& operator<< (ostream& output, const ulamek& g){
output<<g.l<<"/"<<g.m;
return output;
}
istream& operator>> (istream& input, ulamek& g){
input>>g.l;
input.ignore();
input>>g.m;
return input;
}