Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » What is going on here?

This thread is locked; no one can reply to it. rss feed Print
What is going on here?
j0rdant13
Member #14,974
March 2013

Following a tutorial and getting this error:
instances\instances\main.cpp(65): error C2143: syntax error : missing ';' before '.'

Am i missing something or is the compiler taking the piss?

code for the header and .cpp here:

#SelectExpand
1#pragma once 2 3#include <allegro5\allegro.h> 4#include <allegro5\allegro_font.h> 5#include <allegro5\allegro_ttf.h> 6 7#include "GameScreen.h" 8#include "SplashScreen.h" 9#include "TitleScreen.h" 10 11class ScreenManager 12{ 13private: 14 ScreenManager(); 15 ScreenManager(ScreenManager const&); 16 void operator=(ScreenManager const&); 17 18 GameScreen *currentScreen, *newScreen; 19public: 20 static ScreenManager &GetInstance(); 21 ~ScreenManager(void); 22 23 void AddScreen(GameScreen *screen); 24 25 void LoadContent(); 26 void UnloadContent(); 27 void Update(ALLEGRO_EVENT ev); 28 void Draw(ALLEGRO_DISPLAY *display); 29 void Initialize(); 30 31};

.cpp:

#SelectExpand
1#include "ScreenManager.h" 2 3ScreenManager &ScreenManager::GetInstance() 4{ 5 static ScreenManager instance; 6 return instance; 7} 8 9ScreenManager::ScreenManager() 10{ 11} 12 13ScreenManager::~ScreenManager() 14{ 15} 16 17void ScreenManager::AddScreen(GameScreen *screen) 18{ 19 newScreen = screen; 20 currentScreen->UnloadContent(); 21 currentScreen = newScreen; 22 currentScreen->LoadContent(); 23} 24 25void ScreenManager::Initialize() 26{ 27 currentScreen = new SplashScreen(); 28} 29 30void ScreenManager::LoadContent() 31{ 32 currentScreen->LoadContent(); 33} 34 35void ScreenManager::Update(ALLEGRO_EVENT ev) 36{ 37 currentScreen->Update(ev); 38} 39 40void ScreenManager::Draw(ALLEGRO_DISPLAY *display) 41{ 42 currentScreen->Draw(display); 43}

If u need any other code ill supply, ive tried to figure this out and its racking my brain ...

edit:
this is how im declaring stuff in the main:

#SelectExpand
1InputManager input; 2 ScreenManager::GetInstance().Initialize(); 3 ScreenManager::GetInstance().LoadContent(); 4 //---------------- 5 al_start_timer(timerFPS); 6 while(running) 7 { 8 ALLEGRO_EVENT events; 9 al_wait_for_event(event_queue, &events); 10 11 if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 12 { 13 running = false; 14 } 15 if(input.IsKeyPressed(events, ALLEGRO_KEY_ESCAPE)) 16 running = false; 17 if(events.type == ALLEGRO_EVENT_TIMER) 18 { 19 al_get_keyboard_state(&keyState); 20 ScreenManager.GetInstance().Update(events); 21 redraw = true; 22 } 23 24 if(redraw && al_event_queue_is_empty(event_queue)) 25 { 26 ScreenManager.GetInstance().Draw(display); 27 al_flip_display(); 28 al_clear_to_color(al_map_rgb(0,0,0)); 29 } 30 }

Erin Maus
Member #7,537
July 2006
avatar

The error is somewhere in main.cpp. The code you provided is not relevant :P.

As per your edit, to access a static class method or variable you do this:

Foo::Bar()

Not:

Foo.Bar()

In some places, you access the ScreenManager::GetInstance the latter way. You need to do it the former.

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Arthur Kalliokoski
Second in Command
February 2005
avatar

It looks to me like it's complaining about syntax on line 65 (possible a line or three before 65) in main.cpp. Post that.

They all watch too much MSNBC... they get ideas.

j0rdant13
Member #14,974
March 2013

the whole of my main here:

#SelectExpand
1#include <allegro5\allegro.h> 2#include <allegro5\allegro_native_dialog.h> 3#include <allegro5\allegro_native_dialog.h> 4#include <allegro5\allegro_image.h> 5#include <allegro5\allegro_audio.h> 6#include <allegro5\allegro_acodec.h> 7#include <allegro5\allegro_font.h> 8#include <allegro5\allegro_ttf.h> 9 10#include "ScreenManager.h" 11#include "InputManager.h" 12 13#include <iostream> 14#include <vector> 15 16int main() 17{ 18 bool running = true, redraw = false; 19 //------------ 20 if(!al_init()) 21 { 22 al_show_native_message_box(NULL, "Allegro Initialization", "Allegro ERROR:", "Failed to initialize allegro!", NULL, NULL); 23 return -1; 24 } 25 ALLEGRO_DISPLAY* display = al_create_display(800, 600); 26 if(!display) 27 { 28 al_show_native_message_box(NULL, "Allegro Display", "Allegro ERROR:", "Failed to create a display!", NULL, NULL); 29 return -1; 30 } 31 ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue(); 32 ALLEGRO_TIMER* timerFPS = al_create_timer(1.0 / 60); 33 ALLEGRO_KEYBOARD_STATE keyState; 34 //----------------- 35 //al_init_acodec_addon(); 36 al_init_font_addon(); 37 //al_init_image_addon(); 38 al_init_ttf_addon(); 39 al_install_keyboard(); 40 //al_install_mouse(); 41 //-------------- 42 al_register_event_source(event_queue, al_get_display_event_source(display)); 43 al_register_event_source(event_queue, al_get_timer_event_source(timerFPS)); 44 al_register_event_source(event_queue, al_get_keyboard_event_source()); 45 //---------------- 46 InputManager input; 47 ScreenManager::GetInstance().Initialize(); 48 ScreenManager::GetInstance().LoadContent(); 49 //---------------- 50 al_start_timer(timerFPS); 51 while(running) 52 { 53 ALLEGRO_EVENT events; 54 al_wait_for_event(event_queue, &events); 55 56 if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 57 { 58 running = false; 59 } 60 if(input.IsKeyPressed(events, ALLEGRO_KEY_ESCAPE)) 61 running = false; 62 if(events.type == ALLEGRO_EVENT_TIMER) 63 { 64 al_get_keyboard_state(&keyState); 65 ScreenManager.GetInstance().Update(events); 66 redraw = true; 67 } 68 69 if(redraw && al_event_queue_is_empty(event_queue)) 70 { 71 ScreenManager.GetInstance().Draw(display); 72 al_flip_display(); 73 al_clear_to_color(al_map_rgb(0,0,0)); 74 } 75 } 76 77 al_destroy_display(display); 78 al_destroy_timer(timerFPS); 79 al_destroy_event_queue(event_queue); 80 al_uninstall_audio(); 81 al_uninstall_mouse(); 82 al_uninstall_keyboard(); 83 return 0; 84}

thanks for the replies anyways guys this is really annoying

EDIT:
aaron you are absolutley right! why did i even do that lmao!! life saver thanks ever so much and to those for suggestions

Arthur Kalliokoski
Second in Command
February 2005
avatar

It won't compile without all those header files, but

      ScreenManager.GetInstance().Update(events);

on line 65 looks suspicious to me (Disclaimer: I don't do C++)

Should it be

      ScreenManager(GetInstance(Update(events)));

?

They all watch too much MSNBC... they get ideas.

j0rdant13
Member #14,974
March 2013

Thanks Arthur but im calling a static function so therefore i cannot do anything but ScreenManager::GetInstance().Update(); etc.. Thanks anyways :D

Go to: