| sinoo Temat założony przez niniejszego użytkownika | [C++] error C2146: syntax error : missing ';' before identifier » 2012-12-25 21:32:54 Witam, pisząc aplikację napotkałem dziwne błędy, które wyrzucił log. A oto i one: 1>------ Build started: Project: SFML_Game1, Configuration: Debug Win32 ------
 1>Compiling...
 1>main.cpp
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(7) : error C2146: syntax error : missing ';' before identifier 'hero'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(14) : error C2228: left of '.start' must have class/struct/union
 1>        type is 'int'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(25) : error C2664: 'sf::RenderTarget::Draw' : cannot convert parameter 1 from 'int' to 'const sf::Drawable &'
 1>        Reason: cannot convert from 'int' to 'const sf::Drawable'
 1>        No constructor could take the source type, or constructor overload resolution was ambiguous
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(9) : error C2146: syntax error : missing ';' before identifier 'hero'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(9) : error C2086: 'int hero' : redefinition
 1>        e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(7) : see declaration of 'hero'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(17) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'sf::Event::KeyEvent' (or there is no acceptable conversion)
 1>        e:\program files\microsoft sdks\windows\v6.0a\include\guiddef.h(192): could be 'int operator ==(const GUID &,const GUID &)'
 1>        while trying to match the argument list '(sf::Event::KeyEvent, sf::Key::Code)'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(19) : error C3861: 'Colision': identifier not found
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\events.h(20) : error C2228: left of '.Run' must have class/struct/union
 1>        type is 'int'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\main.cpp(7) : error C2146: syntax error : missing ';' before identifier 'hero'
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\main.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\main.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\main.cpp(7) : error C2086: 'int hero' : redefinition
 1>        e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\game1.h(7) : see declaration of 'hero'
 1>Build log was saved at "file://e:\Documents and Settings\SysOp\Moje dokumenty\Visual Studio 2008\Projects\SFML_Game1\SFML_Game1\Debug\BuildLog.htm"
 1>SFML_Game1 - 16 error(s), 0 warning(s)
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
 Wyrzuca go po próbie kompilacji tego kodu: #include <SFML/Graphics.hpp>
 
 #include "Game1.h"
 #include "Events.h"
 
 sf::RenderWindow GameApp( sf::VideoMode( 800, 600, 32 ), "SFML Untitled aplication" );
 Hero hero( 100, 100, true );
 Game1 Game;
 
 int main()
 {
 Game.onStart();
 
 while( GameApp.IsOpened() )
 {
 GameEvent();
 Game.Update();
 Game.Draw();
 }
 return 0;
 }
 
 
 #ifndef Game1_h
 #define Game1_h
 
 #include <SFML/Graphics.hpp>
 
 extern sf::RenderWindow GameApp;
 extern Hero hero;
 
 class Game1
 {
 public:
 void onStart()
 {
 hero.start();
 }
 
 void Update()
 {
 
 }
 
 void Draw()
 {
 GameApp.Clear( sf::Color( 255, 255, 255 ) );
 GameApp.Draw( hero );
 GameApp.Display();
 }
 
 void Exit()
 {
 GameApp.Close();
 }
 };
 
 
 #endif
 
 
 #ifndef Hero_h
 #define Hero_h
 
 #include <SFML/Graphics.hpp>
 
 extern sf::RenderWindow GameApp;
 extern Game1 Game;
 
 struct Hero
 {
 int posX;
 int posY;
 bool flip;
 sf::Image img;
 sf::Sprite sprite;
 float speed;
 
 Hero( int PosX, int PosY, bool Flip )
 : posX( PosX )
 , posY( PosY )
 , Flip( flip )
 { }
 
 public:
 void start()
 {
 img.LoadFromFile( "2.png" );
 sprite.SetImage( img );
 sprite.SetPosition( posX, posY );
 speed = + 1.0;
 sprite.FlipX( flip );
 }
 void Run()
 {
 sprite.Move( speed, 0.0 );
 }
 };
 
 #endif
 
 
 #ifndef Events_h
 #define Events_h
 
 #include <SFML/Graphics.hpp>
 
 sf::Event Event;
 extern sf::RenderWindow GameApp;
 extern Hero hero;
 extern Game1 Game;
 
 void GameEvent()
 {
 while( GameApp.GetEvent( Event ) )
 {
 if( Event.Type == sf::Event::Closed )
 Game.Exit();
 
 if( Event.Key == sf::Key::D )
 {
 if( Colision() != true )
 hero.Run();
 
 }
 
 }
 }
 
 bool Colision()
 {
 return false;
 }
 
 #endif
 
Kompletnie tego nie rozumiem, gdyż przejrzałem dokładnie cały kod i nigdzie, a w szczególności w i po klasie "Hero" nie brakuje średnika. Reszta błędów wynika najprawdopodobniej z tego jednego, więc niema co się nimi przejmować. Już nie raz przekonałem się, że mogę na was liczyć i mam nadzieję, że z tym też dacie radę ;)Link do Bibliotek: http://sfml-dev.org/ | 
|  | 
| DejaVu | » 2012-12-25 22:08:17 Po prostu klasa "Hero" jest nieznana :) | 
|  | 
| sinoo Temat założony przez niniejszego użytkownika | » 2012-12-26 10:06:37 Nie rozumiem... Przecież zadeklarowałem  Hero hero  w pliku głównym - main.cpp, a w plikach nagłówkowych załączyłem przez  extern Hero hero | 
|  | 
| LukiPRO | » 2012-12-26 10:17:12 A nie zapomniałeś dodać #include "Hero.h" do main.cpp? | 
|  | 
| sinoo Temat założony przez niniejszego użytkownika | » 2012-12-26 10:23:11 No rzeczywiście, ale po dodaniu ciągle wywala ten sam błąd, tyle, że w odniesieniu do klasy Game. Oto fragment logu:  1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\hero.h(7) : error C2146: syntax error : missing ';' before identifier 'Game'1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\hero.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>e:\documents and settings\sysop\moje dokumenty\visual studio 2008\projects\sfml_game1\sfml_game1\hero.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 | 
|  | 
| jsc | » 2012-12-26 12:35:39 Teraz tam brakuje deklaracji hero. | 
|  | 
| sinoo Temat założony przez niniejszego użytkownika | » 2012-12-26 17:52:12 | Teraz tam brakuje deklaracji hero. | 
 Hymm... przeciez jest odwołanie  extern Hero hero | 
|  | 
| jsc | » 2012-12-26 17:55:27 Ale bez include extern nie działa. | 
|  | 
| « 1 »  2 |