Leniwy Temat założony przez niniejszego użytkownika |
» 2011-01-27 22:34:16 83 `left' is not a type 83 request for member of non-aggregate type before ')' token 85 `left' is not a type 85 request for member of non-aggregate type before ')' token 87 `ile' has not been declared 87 request for member of non-aggregate type before '=' token 87 `left' is not a type 87 request for member of non-aggregate type before '->' token 87 `right' is not a type 87 request for member of non-aggregate type before '->' token 88 no matching function for call to `std::priority_queue<Huff, std::vector<Huff, std::allocator<Huff> >, std::less<Huff> >::push(Huff*&)' note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_queue.h:428 candidates are: void std::priority_queue<_Tp, _Sequence, _Compare>::push(const typename _Sequence::value_type&) [with _Tp = Huff, _Sequence = std::vector<Huff, std::allocator<Huff> >, _Compare = std::less<Huff>] C:\Users\Serek\UKSW\Makefile.win [Build Error] [kod.o] Error 1 Jeszcze więcej błedów ... :/ ps. numery lini kodu się zmieniły bo dodałem komentarze, nic w klasie nie zmieniałem |
|
malan |
» 2011-01-27 22:36:37 Gdyż zapewne modyfikowałeś jakieś zmienne/obiekty w programie. Ja pracowałem na kodzie, który wkleiłeś w pierwszym poście. Nic, poza pętlą nie zmieniałem... |
|
Leniwy Temat założony przez niniejszego użytkownika |
» 2011-01-27 23:22:42 #include <cstdlib> #include <iostream> #include <string> #include <queue>
using namespace std;
class Huff { public: int ile; char co; Huff * left; Huff * right; public: Huff() { }; Huff( int i, char j ) { this->ile = i; this->co = j; this->left = NULL; this->right = NULL; } friend bool operator <( const Huff & x, const Huff & y ) { if( x.ile > y.ile ) return true; else return false; } Huff & operator =( Huff & y ) { this->co = y.co; this->ile = y.ile; this->left = y.left; this->right = y.right; return * this; } };
int main() { int ASCII[ 128 ] = { 0 }; FILE * plik; char znak; int pom; plik = fopen( "text.txt", "r" ); if( plik == NULL ) { cout << "Brak pliku text.txt! \a" << endl << endl; } else { cout << "Wczytany tekst:" << endl; while( !feof( plik ) ) { fscanf( plik, "%c", & znak ); printf( "%c", znak ); pom =( int ) znak; ASCII[ pom ] += 1; }; cout << endl << endl; }; fclose( plik ); priority_queue < Huff > PQ; for( int i = 0; i < 128; i++ ) { if( ASCII[ i ] != 0 ) PQ.push( Huff( ASCII[ i ],( char ) i ) ); }; Huff * pomo = new Huff; while( !PQ.empty() ) { ( * pomo.left ) = PQ.top(); PQ.pop(); ( * pomo.right ) = PQ.top(); PQ.pop(); pomo.ile = pomo.left->ile + pomo.right->ile; PQ.push( pomo ); }; system( "PAUSE" ); return EXIT_SUCCESS; }
Tak u Ciebie działało? :| bo u mnie ciągle generuje błędy... a w czym pisałeś? może to kwestia środowiska. Ja używam Dev C++. ps. Jest jakiś tutorial do tych znaczników? Bo znaleźć nie mogłem ;P |
|
malan |
» 2011-01-28 00:02:51 Mówię, że zmieniłeś coś w kodzie, to Ty swoje. Przypatrz się uważnie: #include "stdafx.h"
using namespace std;
class Huff { public: int ile; char co; Huff * left; Huff * right; public: Huff() { }; Huff( int i, char j ) { this->ile = i; this->co = j; this->left = NULL; this->right = NULL; } friend bool operator <( const Huff & x, const Huff & y ) { if( x.ile > y.ile ) return true; else return false; } Huff & operator =( Huff & y ) { this->co = y.co; this->ile = y.ile; this->left = y.left; this->right = y.right; return * this; } };
int main() { int ASCII[ 128 ] = { 0 }; FILE * plik; char znak; int pom; plik = fopen( "text.txt", "r" ); if( plik == NULL ) { cout << "Brak pliku text.txt! \a" << endl << endl; } else { cout << "Wczytany tekst:" << endl; while( !feof( plik ) ) { fscanf( plik, "%c", & znak ); printf( "%c", znak ); pom =( int ) znak; ASCII[ pom ] += 1; }; cout << endl << endl; }; fclose( plik ); priority_queue < Huff > PQ; for( int i = 0; i < 128; i++ ) { if( ASCII[ i ] != 0 ) PQ.push( Huff( ASCII[ i ],( char ) i ) ); }; Huff pomo, * Root; while( !PQ.empty() ) { ( * pomo.left ) = PQ.top(); PQ.pop(); ( * pomo.right ) = PQ.top(); PQ.pop(); pomo.ile = pomo.left->ile + pomo.right->ile; PQ.push( pomo ); }; system( "PAUSE" ); return EXIT_SUCCESS; }
1>------ Build started: Project: 3619, Configuration: Release Win32 ------ 1> 3619.cpp 1>3619.cpp(47): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> ...\include\stdio.h(234) : see declaration of 'fopen' 1>3619.cpp(53): warning C4996: 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> ...\include\stdio.h(253) : see declaration of 'fscanf' 1>3619.cpp(70): warning C4101: 'Root' : unreferenced local variable 1> Generating code 1> Finished generating code 1> 3619.vcxproj -> ...\Release\3619.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Poza tym z takimi błędami powinieneś sobie radzić, więc albo wróć do kursu albo czytaj, co krzyczy kompilator ;) |
|
Leniwy Temat założony przez niniejszego użytkownika |
» 2011-01-28 00:27:36 Oj coś się dogadać nie możemy ;P Chodzi mi o to że nasze, różne środowiska wypluwają różne błędy. Utworzyłem nowy projekt u siebie i wkleiłem tam Twój kod podmieniając jedynie biblioteki. Z #include "stdafx.h" na: #include <cstdlib> #include <iostream> #include <string> #include <queue> dla jasności Reszta kodu jest taka sama. A jednak generuje różne błędy. U mnie ciągle czepia się o operatory, a u Ciebie o operacje na plikach... Chyba nie powiesz mi że: C:\Users\Serek\Desktop\cfhjf\main.cpp In function `int main()': 75 C:\Users\Serek\Desktop\cfhjf\main.cpp no match for 'operator=' in '*pomo.Huff::left = (&PQ)->std::priority_queue<_Tp, _Sequence, _Compare>::top [with _Tp = Huff, _Sequence = std::vector<Huff, std::allocator<Huff> >, _Compare = std::less<Huff>]()' note C:\Users\Serek\Desktop\cfhjf\main.cpp:32 candidates are: Huff& Huff::operator=(Huff&) 77 C:\Users\Serek\Desktop\cfhjf\main.cpp no match for 'operator=' in '*pomo.Huff::right = (&PQ)->std::priority_queue<_Tp, _Sequence, _Compare>::top [with _Tp = Huff, _Sequence = std::vector<Huff, std::allocator<Huff> >, _Compare = std::less<Huff>]()' note C:\Users\Serek\Desktop\cfhjf\main.cpp:32 candidates are: Huff& Huff::operator=(Huff&) C:\Users\Serek\Desktop\cfhjf\Makefile.win [Build Error] [main.o] Error 1
to to samo co: 1>------ Build started: Project: 3619, Configuration: Release Win32 ------ 1> 3619.cpp 1>3619.cpp(47): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> ...\include\stdio.h(234) : see declaration of 'fopen' 1>3619.cpp(53): warning C4996: 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> ...\include\stdio.h(253) : see declaration of 'fscanf' 1>3619.cpp(70): warning C4101: 'Root' : unreferenced local variable 1> Generating code 1> Finished generating code 1> 3619.vcxproj -> ...\Release\3619.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Albo po prostu nie rozumiem błędów generowanych przez Visuala ;P ps. Aby nie było że jestem idiotą co nie wie co się dzieje: rozumiem na czym polega problem tylko mnie intryguje różnica w błędach :P |
|
malan |
» 2011-01-28 14:35:30 Odpowiedź masz tu: Przeciążanie operatorów w C++.
Poza tym, powiedz mi, po co używasz takiego zapisu: this->co = y.co; zamiast co = y.co; ?
edit:
Visual rzuca warningami (dot. dwóch funkcji), a nie błędami ;p.
Co do różnicy w procesie kompilacji, to widocznie kompilator, którego używa Visual sam sobie z Huff & wtf zrobił const Huff & wtf . |
|
Elaine |
» 2011-01-28 14:48:57 Co do różnicy w procesie kompilacji, to widocznie kompilator, którego używa Visual sam sobie z Huff & wtf zrobił const Huff & wtf . |
Nie, kompilator Microsoftu po prostu ma takie jedno rozszerzenie, które pozwala na podpięcie wartości do niestałej referencji. Przy najwyższym poziomie ostrzeżeń zwykle ostrzega o tym, że zostało użyte, ale tu jak widać nie ostrzegł. |
|
Leniwy Temat założony przez niniejszego użytkownika |
» 2011-01-29 10:59:19 Kompiluje się xD Tu już dokończony kod, jak by ktoś kiedyś szukał i tu zahaczył ;) #include <cstdlib> #include <iostream> #include <fstream> #include <string> #include <queue> #include <map> #include <cstdio>
using namespace std;
class Huff { public: int ile; char co; Huff * left; Huff * right; public: Huff() { }; Huff( int i, char j ) { this->ile = i; this->co = j; this->left = NULL; this->right = NULL; } friend bool operator <( const Huff & x, const Huff & y ) { if( x.ile > y.ile ) return true; else return false; } };
int main() { int ASCII[ 128 ] = { 0 }; FILE * plik; char znak; int pom; plik = fopen( "text.txt", "r" ); if( plik == NULL ) { cout << "Brak pliku text.txt! \a" << endl << endl; } else { cout << "Wczytany tekst:" << endl; while( !feof( plik ) ) { fscanf( plik, "%c", & znak ); printf( "%c", znak ); pom =( int ) znak; ASCII[ pom ] += 1; }; cout << endl << endl; }; fclose( plik ); priority_queue < Huff * > PQ; for( int i = 0; i < 128; i++ ) { Huff * wsk; wsk = new Huff( ASCII[ i ],( char ) i ); if( ASCII[ i ] != 0 ) PQ.push( wsk ); }; cout << " Kolejka utworzona" << endl << endl; Huff * pomo, * Root; while( !PQ.empty() ) { pomo->left = PQ.top(); PQ.pop(); pomo->right = PQ.top(); PQ.pop(); pomo->ile = pomo->left->ile + pomo->right->ile; PQ.push( pomo ); Root = pomo; }; cout << " Drzewo zbudowane" << endl << endl; cout << " Koniec" << endl << endl; system( "PAUSE" ); return EXIT_SUCCESS; }
|
|
1 « 2 » 3 |