Bajt Temat założony przez niniejszego użytkownika |
[C++] typedef unsigned int UINT - syntax error : 'int' should be preceded by ';' » 2013-07-10 13:48:18 Witam
Mam pewien problem. Otóż piszę pewien program i wszystko się kompilowało - od czasu. W moim programie użyłem instrukcji typedef aby skrócić czas wypisywania nazw typów zmiennych. Już na początku dodałem to do mojego programu - i wszystko ładnie się kompilowało. Teraz jednak, wygląda na to, że coś jest źle.
Program podzielony jest na 3 pliki źródłowe i 1 plik nagłówkowy. Kiedy próbuje skompilować całość, wywala błąd:
1>------ Build started: Project: Paper Stone Scrissors Game, Configuration: Debug Win32 ------
1> menu.cpp
1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\menu.cpp(6): error C2144: syntax error : 'unsigned int' should be preceded by ';'
1> main.cpp
1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\main.cpp(10): error C2144: syntax error : 'unsigned int' should be preceded by ';'
1> game.cpp
1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\game.cpp(10): error C2144: syntax error : 'unsigned int' should be preceded by ';'
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Przesyłam również pierwsze linijki, w których kompilator dopatrzył się błędu:
Plik menu.cpp
#include <iostream> #include <Windows.h> #include <conio.h> #include "functions.h"
typedef unsigned int UINT; typedef unsigned short int US_INT; typedef unsigned long long int USL_INT;
const UINT TAB = 31; const UINT TAB1 = 19;
Plik main.cpp
#include <iostream> #include <conio.h> #include <cstdlib> #include <ctime> #include <string> #include <fstream> #include <Windows.h> #include "functions.h"
typedef unsigned int UINT; typedef unsigned short int US_INT; typedef unsigned long long int USL_INT;
int key; int type_game;
Plik game.cpp
#include <iostream> #include <conio.h> #include <cstdlib> #include <ctime> #include <string> #include <fstream> #include <Windows.h> #include "functions.h"
typedef unsigned int UINT; typedef unsigned short int US_INT; typedef unsigned long long int USL_INT;
struct INFO { US_INT __rounds; std::string names[ 2 ]; US_INT score_player[ 2 ]; }; struct SCORE_PLAYER { std::string name; int score_player; };
std::string names[ 2 ]; const US_INT SLEEP_TIME = 1000; const US_INT TAB = 31; char key_keyboard; char type_weapon, type_weapon1; char choose_end; int key1 = 0, key2 = 0; int counter_rounds = 1; INFO game_options; SCORE_PLAYER game_vs_computer;
W tych linijkach nie ma nic interesującego, więc gdzie wkradł się błąd?
|
|
DejaVu |
» 2013-07-10 13:58:14 |
|
Bajt Temat założony przez niniejszego użytkownika |
» 2013-07-10 14:13:52 Cóż, usunąłem wszystkie typedef'y, w związku z czym musiałem pozmieniać również nazwy typów zmiennych. Teraz wogóle nie ograniam. 1>------ Build started: Project: Paper Stone Scrissors Game, Configuration: Debug Win32 ------ 1> menu.cpp 1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\menu.cpp(8): error C2144: syntax error : 'int' should be preceded by ';' 1> main.cpp 1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\main.cpp(12): error C2144: syntax error : 'int' should be preceded by ';' 1> game.cpp 1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\game.cpp(13): error C2143: syntax error : missing ';' before '<class-head>' 1>c:\users\user\documents\programs c++\paper stone scrissors game\paper stone scrissors game\paper stone scrissors game\game.cpp(261): warning C4018: '<' : signed/unsigned mismatch 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Plik menu.cpp #include <iostream> #include <Windows.h> #include <conio.h> #include "functions.h"
int TAB = 31; int TAB1 = 19;
Plik main.cpp #include <iostream> #include <conio.h> #include <cstdlib> #include <ctime> #include <string> #include <fstream> #include <Windows.h> #include "functions.h"
int key; int type_game;
Plik game.cpp #include <iostream> #include <conio.h> #include <cstdlib> #include <ctime> #include <string> #include <fstream> #include <Windows.h> #include "functions.h"
struct INFO { unsigned int __rounds; std::string names[ 2 ]; unsigned int score_player[ 2 ]; }; struct SCORE_PLAYER { std::string name; int score_player; };
std::string names[ 2 ]; const unsigned int SLEEP_TIME = 1000; const unsigned int TAB = 31; char key_keyboard; char type_weapon, type_weapon1; char choose_end; int key1 = 0, key2 = 0; int counter_rounds = 1; INFO game_options; SCORE_PLAYER game_vs_computer;
I ostrzeżenie, którego wogóle przedtem nie było void GameForPlayers( void ) { for( int __counter_loop = 0; __counter_loop < game_options.__rounds; __counter_loop++ ) { DrawCountdown(); DrawTypesWeaponsPlayer1(); DrawScreenForChangePlayer(); DrawTypesWeaponsPlayer2(); CheckGame(); } DrawStatistics(); }
|
|
Monika90 |
» 2013-07-10 14:24:47 Być może masz błąd w pliku "functions.h". Poza tym nazwy zaczynające się od dwóch znaków podkreślenia są zarezerwowane dla implementacji.
|
|
Bajt Temat założony przez niniejszego użytkownika |
» 2013-07-10 14:35:26 Cóż, problem rozwiązany, wystarczyło usunąć prototyp funkcji z pliku nagłówkowego. @Monika Zaiste, tak jest. Jednak dalej to nie tłumaczy faktu, dlaczego właśnie teraz kompilator pokazuje mi ostrzeżenie, a nie 2 dni temu, przy deklaracji tej zmiennej. |
|
Monika90 |
» 2013-07-10 14:41:19 Jeżeli Ci chodzi o: game.cpp(261): warning C4018: '<' : signed/unsigned mismatch typ zmiennej __rounds był unsigned short, które jest promowane do int, więc porównywałeś int z int, a teraz jest unsigned int, które nie podlega promocji, wiec porównujesz int z unsigned int i stąd warning. |
|
pekfos |
» 2013-07-10 18:42:16 Poza tym nazwy zaczynające się od dwóch znaków podkreślenia są zarezerwowane dla implementacji. |
Nazwy w globalnej przestrzeni nazw, zaczynające się od dwóch znaków podkreślenia, są zarezerwowane dla implementacji ;) |
|
Elaine |
» 2013-07-10 18:43:57 Nie. Wszystkie nazwy zawierające podwójne podkreślenie, oraz te, które zaczynają się podkreśleniem i dużą literą, są zarezerwowane dla implementacji. Nazwy zaczynające się pojedynczym podkreśleniem zdefiniowane w globalnej przestrzeni nazw są również zarezerowane dla implementacji. 17.6.4.3.2/1: Certain sets of names and function signatures are always reserved to the implementation: — Each name that contains a double underscore __ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use. — Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace. |
|
|
« 1 » 2 |