Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Błąd podczas linkowania klasy

Ostatnio zmodyfikowano 2014-06-25 18:16
Autor Wiadomość
qest43
Temat założony przez niniejszego użytkownika
Błąd podczas linkowania klasy
» 2014-06-23 20:26:43
Mam sobie klasę:

C/C++
#pragma once

#include <iostream>
#include <string>
#include<map>
#include "GameScreen.h"
#include "SplashScreen.h"
#include "MenuScreen.h"



//Allegro Inits
#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include <map>

#define ScreenWidth 800
#define ScreenHeight 600

class ScreenManager
{
private:
    ScreenManager();
    ScreenManager( ScreenManager const & );
    void operator =( ScreenManager const & );
   
    GameScreen * currentScreen;
   
    std::map < std::string, GameScreen *> screenDirectory;
   
public:
    ~ScreenManager();
    static ScreenManager & GetInstance();
   
    void AddScreen( std::string newScreen );
   
    void Initialize();
    void LoadContent();
    void UnloadContent();
    void Update( ALLEGRO_EVENT ev );
    void Draw( ALLEGRO_DISPLAY * display );
};


I klasę:
C/C++
#pragma once

#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include "FileManager.h"
#include "InputManager.h"
#include "ScreenManager.h"

class MenuManager
{
private:
    FileManager fileManager;
    InputManager input;
   
    std::vector < std::string > attributes;
    std::vector < std::vector < std::string >> contents;
   
    ALLEGRO_BITMAP * image;
    ALLEGRO_FONT * font;
    std::vector < std::string > items;
    std::vector < std::pair < float, float >> position;
    std::vector < std::string > menuLinks;
    std::pair < float, float > newImageSize;
    std::pair < float, float > imageSize;
   
    int align;
    int active;
    int itemColor;
    int itemNumber;
   
    void SetItems();
   
public:
    MenuManager( void );
    ~MenuManager( void );
   
    void LoadContent( std::string idMenu );
    void UnloadContent();
    void Update( ALLEGRO_EVENT ev );
    void Draw( ALLEGRO_DISPLAY * display );
};
 
 



Gdy wstawiam #include"ScreenManager" do tej klasy:

C/C++
#pragma once

#include <allegro5\allegro.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include "GameScreen.h"
#include "MenuManager.h"

class MenuScreen
    : public GameScreen
{
private:
    MenuManager menu;
public:
    MenuScreen( void );
    ~MenuScreen( void );
   
    void LoadContent();
    void UnloadContent();
    void Update( ALLEGRO_EVENT ev );
    void Draw( ALLEGRO_DISPLAY * display );
};


Otrzymuję błąd: Error    1    error C2146: syntax error : missing ';' before identifier 'menu
Nie wiem gdzie leży problem, dodaję jeszcze jedną klasę:

C/C++
#pragma once

#include<allegro5\allegro.h>
#include<vector>
#include"InputManager.h"
#include"FileManager.h"

class GameScreen
{
protected:
    InputManager input;
    FileManager fileManager;
   
    std::vector < std::string > attributes;
    std::vector < std::vector < std::string >> contents;
public:
    GameScreen();
    ~GameScreen();
   
    virtual void LoadContent();
    virtual void UnloadContent();
    virtual void Update( ALLEGRO_EVENT ev );
    virtual void Draw( ALLEGRO_DISPLAY * display );
}
P-112596
Jacob99
» 2014-06-23 20:40:55
Możesz podać cały log?
P-112597
qest43
Temat założony przez niniejszego użytkownika
» 2014-06-23 20:44:42
Error 1 error C2146: syntax error : missing ';' before identifier 'menu' c:\users\abc\documents\visual studio 2012\projects\rpgt\rpgt\menuscreen.h 12 1 rpgt
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\abc\documents\visual studio 2012\projects\rpgt\rpgt\menuscreen.h 12 1 rpgt[/cod]
P-112598
Jacob99
» 2014-06-23 21:06:47
Nie wiem co wywołuje ten błąd składniowy, ale do MenuScreen.h (czy jak tam nazwałeś ten nagłówek) nie musisz, a wręcz nie powinieneś wstawiać ScreenManager.h, bo już go dołączyłeś poprzez MenuManager.h

P.S. W ScreenManager.h dwukrotnie dołączasz nagłówek map.
A do nagłówków powinieneś stawiać "strażnika"
#ifndef
P-112599
pekfos
» 2014-06-23 21:11:04
A do nagłówków powinieneś stawiać "strażnika"
#ifndef
Ma #pragma once.
P-112601
qest43
Temat założony przez niniejszego użytkownika
» 2014-06-23 21:13:19
Źle opisałem sytuację. Gdy dodaję ScreenManager.h do MenuManagera to ten błąd wyskakuję. MenuManager jest linkowany właśnie do MenuScreen gdzie następnie nie rozpoznaje zmiennej MenuManagera. Gdy nie dodaję ScreenManagera do MenuManagera wszystko jest okej.
P-112602
pekfos
» 2014-06-23 21:18:56
Błąd jest dlatego, że typ MenuManager, z powodu sposobu dołączania nagłówków, jest nieznany tam, gdzie chcesz go użyć. Albo to wina niepotrzebnych nagłówków, albo wadliwości zależności między klasami - aż tak dokładnie nie sprawdzałem.
P-112603
qest43
Temat założony przez niniejszego użytkownika
» 2014-06-23 21:35:14
Posprawdzałem wszystkie nagłówki, uporządkowałem, dalej nic, nie wiem gdzie jak ja mam ten błąd rozwiązać.
P-112608
« 1 » 2 3
  Strona 1 z 3 Następna strona