Witam wszystkich,
Mam problem z umieszczeniem przeciążeń operatów "<<" oraz ">>" w module. Przed przeniesieniem przeciążeń wszystko było ok. Mój aktualny kod wygląda tak:
plik "przeciazenia.hh"
#ifndef PRZECIAZENIA_HH
#define PRZECIAZENIA_HH
#include <iostream>
#include <fstream>
#include "wektor.hh"
#include "macierz.hh"
#include "uklad.hh"
float operator*(wektor a, wektor b);
ostream& operator<<(ostream& output, uklad_rownan& uklad);
ostream& operator<<(ostream& output, macierz3x3& a);
istream& operator>>(istream& input, wektor& b);
#endif
plik "przeciazenia.cpp":
#include <iostream>
#include <cstdlib>
#include <fstream>
#include "przeciazenia.hh"
#include "wektor.hh"
#include "macierz.hh"
#include "uklad.hh"
float operator*(wektor a, wektor b){
return ((a[0]*b[0])+(a[1]*b[1])+(a[2]*b[2]));
}
ostream& operator<<(ostream& output, uklad_rownan& uklad){
for(int i=0;i<3;i++)
{
output << uklad.a[i][0] << "x";
if(uklad.a[i][1] >= 0)
output << "+";
output << uklad.a[i][1] << "y";
if(uklad.a[i][2] >= 0)
output << "+";
output << uklad.a[i][2] << "z" << " = " << uklad.b[i] << endl << endl;
}
return output;
}
ostream& operator<<(ostream& output, macierz3x3& a){
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
output << a[i][j] << "\t";
output << endl << endl;
}
return output;
}
istream& operator>>(istream& input, wektor& b){
input >> b[0] >> b[1] >> b[2];
return input;
}
plik "main.cpp":
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include "macierz.hh"
#include "wektor.hh"
#include "uklad.hh"
#include "przeciazenia.hh"
using namespace std;
void menu(){
cout << "..::MENU::.." << endl
<< "a - Wczytaj macierz wspolczynnikow A" << endl
<< "b - Wczytaj wektor wyrazow wolnych b" << endl
<< "w - Wczytaj wszystkie wspolczynniki (A i b)" << endl
<< "p - Pokaz rownanie" << endl
<< "r - Rozwiaz, pokaz wynik i blad" << endl
<< "? - Wyswietl menu" << endl
<< "k - Koniec dzialania programu" << endl;
}
int main(){
uklad_rownan uklad;
menu();
char wybor[10];
while(true){
cout << "Twoj wybor: ";
cin >> wybor;
// tutaj znajduje sie "prawdziwe" menu
switch(*wybor){
case'a':
int a[3];
cout << "Wprowadz wspolczynniki macierzy A." << endl
<< "Nalezy je podac w kolejnosci:" << endl
<< "A_11 A_12 A_13" << endl
<< "A_21 A_22 A_23" << endl
<< "A_31 A_32 A_33" << endl;
for (int i=0; i<3; i++){
cin >> a[0] >> a[1] >> a[2];
for (int j=0; j<3; j++)
uklad.a[i][j] = a[j];
}
break;
case'b':
cout << "Wprowadz wspołczynniki wektora wyrazow wolnych." << endl
<< "Nalezy je podac w kolejnosci: b[0] b[1] b[2] itd." << endl;
cin >> uklad.b[0] >> uklad.b[1] >> uklad.b[2];
break;
case'w':
cout << "Wprowadz wspolczynniki dla calego ukladu rownan." << endl
<< "Nalezy je podac w kolejnosci:" << endl
<< "A_11 A_12 A_13 b_1" << endl
<< "A_21 A_22 A_23 b_2" << endl
<< "A_31 A_32 A_33 b_3" << endl;
int ab[4];
for (int i=0; i<3; i++){
cin >> ab[0] >> ab[1] >> ab[2] >> ab[3];
for (int j=0; j<3; j++)
uklad.a[i][j] = ab[j];
uklad.b[i]=ab[3];
}
break;
case'p':
cout << "Powstały uklad rownan to:" << endl << uklad;
break;
case'r':
uklad.rozwiaz_uklad();
break;
case'?':
menu();
break;
case'k':
cout << "Dziekuje za skorzystanie z programu i zapraszam ponownie." << endl;
return 0;
default:
cerr << "Niepoprawny wybor. Sprobuj ponownie." << endl
<< "(Jesli nie pamietasz opcji wyboru, wyswietl menu -> '?')" << endl;
break;
}
}
}
plik "Makefile":
__start__: a.out
./a.out
a.out: main.o wektor.o macierz.o uklad.o przeciazenia.o
g++ main.o wektor.o macierz.o uklad.o przeciazenia.o
wektor.o: wektor.cpp wektor.hh
g++ -c -Wall -pedantic wektor.cpp
macierz.o: macierz.cpp macierz.hh
g++ -c -Wall -pedantic macierz.cpp
uklad.o: uklad.cpp uklad.hh wektor.hh macierz.hh przeciazenia.hh
g++ -c -Wall -pedantic uklad.cpp
przeciazenia.o: przeciazenia.cpp przeciazenia.hh wektor.hh macierz.hh uklad.hh
g++ -c -Wall -pedantic przeciazenia.cpp
main.o: main.cpp macierz.hh wektor.hh uklad.hh przeciazenia.hh
g++ -c -Wall -pedantic main.cpp
A oto błędy przy kompilacji:
In file included from main.cpp:13:
przeciazenia.hh:19: error: expected constructor, destructor, or type conversion before ‘&’ token
przeciazenia.hh:27: error: expected constructor, destructor, or type conversion before ‘&’ token
przeciazenia.hh:36: error: expected constructor, destructor, or type conversion before ‘&’ token
main.cpp: In function ‘int main()’:
main.cpp:77: error: no match for ‘operator<<’ in ‘((std::basic_ostream<char, std::char_traits<char> >*)std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Powsta\37777777705\37777777602y uklad rownan to:")))->std::basic_ostream<_CharT, _Traits>::operator<< [with _CharT = char, _Traits = std::char_traits<char>](std::endl [with _CharT = char, _Traits = std::char_traits<char>]) << uklad’
/usr/include/c++/4.4/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]...
(i tak dalej...)
make: *** [main.o] Błąd 1
Dosłownie kilka linijek z "main.cpp" wyciąłem z racji zbędnych uwag oraz danych osobowych ;)
Za wszelką pomoc z góry dziękuję.