2012-11-10 4 views
5

Otrzymuję błędy z moją klasą GraphicsManager.Błędy w C++: żądanie dla członka "..." w "grmanager", który jest typu nieklasowanego "GraphicsManager"

GraphicsManager.cpp:

#include "C:\Users\Chris Uzzolina\Desktop\obj\include\GraphicsManager.h" 
#include <SDL.h> 
#include <string> 
GraphicsManager::GraphicsManager(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *screen) 
{ 

} 

GraphicsManager::~GraphicsManager() 
{ 
    //dtor 
} 
bool init(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *scr) 
{ 
    //Initialize all SDL subsystems 
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1) 
    { 
     return false; 
    } 

    //Set up the screen 
    scr = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); 

    //If there was an error in setting up the screen 
    if(scr == NULL) 
    { 
     return false; 
    } 

    //Set the window caption 
    SDL_WM_SetCaption("Event test", NULL); 

    //If everything initialized fine 
    return true; 
} 

SDL_Surface *load_image(std::string filename) 
{ 
    //Temporary storage for the image that's loaded 
    SDL_Surface* loadedImage = NULL; 

    //The optimized image that will be used 
    SDL_Surface* optimizedImage = NULL; 
    //Load the image 
    loadedImage = SDL_LoadBMP(filename.c_str()); 
    //If nothing went wrong in loading the image 
    if(loadedImage != NULL) 
    { 
     //Create an optimized image 
     optimizedImage = SDL_DisplayFormat(loadedImage); 

     //Free the old image 
     SDL_FreeSurface(loadedImage); 
    } 
    //Return the optimized image 
    return optimizedImage; 
} 

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination) 
{ 
    //Make a temporary rectangle to hold the offsets 
    SDL_Rect offset; 

    //Give the offsets to the rectangle 
    offset.x = x; 
    offset.y = y; 
    //Blit the surface 
    SDL_BlitSurface(source, NULL, destination, &offset); 
} 

void clean_up(SDL_Surface *image) 
{ 
    //Free the image 
    SDL_FreeSurface(image); 
} 

void quit_sdl() 
{ 
    SDL_Quit(); 
} 

GraphicsManager.h:

#ifndef GRAPHICSMANAGER_H 
#define GRAPHICSMANAGER_H 
#include <string> 
#include<SDL.h> 
class GraphicsManager 
{ 
public: 
    GraphicsManager(); 
    GraphicsManager(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *screen); 
    virtual ~GraphicsManager(); 
    bool init(int SCREEN_WIDTH, int SCREEN_HEIGHT, int SCREEN_BPP, std::string caption, SDL_Surface *screen); 
    SDL_Surface *load_image(std::string filename); 
    void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination); 
    void clean_up(SDL_Surface *image); 
    void quit_sdl(); 
protected: 
private: 
}; 

#endif // GRAPHICSMANAGER_H 

SDLLesson01.cpp:

#include "SDL/SDL.h" 
#include "SDL/SDL_image.h" 
#include <string> 
#include "C:\Users\Chris Uzzolina\Desktop\obj\include\GraphicsManager.h" 

int SCREEN_WIDTH = 640; 
int SCREEN_HEIGHT = 480; 
int SCREEN_BPP = 32; 
SDL_Surface *message = NULL; 
SDL_Surface *background = NULL; 
SDL_Surface *screen = NULL; 
std::string caption = "THProject"; 
SDL_Event event; 

int main(int argc, char* args[]) 
{ 
    bool quit=false; 
    GraphicsManager grmanager(); 
    grmanager.init(SCREEN_WIDTH , SCREEN_HEIGHT , SCREEN_BPP , caption , screen); 
    message = grmanager.load_image("riku.bmp"); 
    background = grmanager.load_image("abc.bmp"); 
    grmanager.apply_surface(0, 0, background, screen); 
    grmanager.apply_surface(320, 0, background, screen); 
    grmanager.apply_surface(0, 240, background, screen); 
    grmanager.apply_surface(320, 240, background, screen); 
    grmanager.apply_surface(180, 140, message, screen); 
    if(SDL_Flip(screen) == -1) 
    { 
     return 1; 
    } 
    while(quit==false) 
    { 
     while(SDL_PollEvent(&event)) 
     { 
      if (event.type== SDL_QUIT) 
      { 
       quit=true; 
      } 
     } 
    } 
    grmanager.clean_up(message); 
    grmanager.clean_up(background); 
    grmanager.quit_sdl(); 
    return 0; 
} 

Dotychczas Szukałem wokół wielu błędów na tej stronie i zostałem zaskoczony moim ostatnim błędem. Jeśli ktokolwiek może zaoferować wgląd w ten problem, będzie to docenione. Używam systemu Windows Vista i używam Code::Blocks z kompilatorem mingw i bibliotekami SDL. Oto komunikaty produkcji:

C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp||In function 'int SDL_main(int, char**)':| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|20|error: request for member 'init' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|21|error: request for member 'load_image' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|22|error: request for member 'load_image' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|23|error: request for member 'apply_surface' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|24|error: request for member 'apply_surface' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|25|error: request for member 'apply_surface' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|26|error: request for member 'apply_surface' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|27|error: request for member 'apply_surface' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|42|error: request for member 'clean_up' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|43|error: request for member 'clean_up' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
C:\Users\Chris Uzzolina\Desktop\obj\SDLLesson01.cpp|44|error: request for member 'quit_sdl' in 'grmanager', which is of non-class type 'GraphicsManager()'| 
||=== Build finished: 11 errors, 0 warnings ===| 
+4

Większość Vexing Parse znów uderza! – chris

+0

Huh? Co znaczy thta? – user1812530

+0

Jest tam wyraźny termin Google;) – chris

Odpowiedz

0

W kodzie masz:

GraphicsManager grmanager(); 

Myślisz, że to oświadczenie var nazywa grmanager typu GraphicsManager i zmuszając wywołanie konstruktora domyślnego. Ale tak naprawdę jest to deklaracja funkcji zwana grmanager, która zwraca graficznego menedżera grafiki i nie przyjmuje żadnych argumentów. Więc kompilator nie rozumie

grmanager.Init(...) 

jak dla niego, grmanager jest funkcja imię.

Spróbuj zastąpić swoją deklarację po prostu Grmanager GraphicsManager;

Powinno być ok, jeśli nie przekazywać argumenty do konstruktora, jest to jeden domyślny, który jest nazywany (chyba że masz ciemną duszę i stworzył tylko jeden konstruktor tylko argumenty o wartości domyślnej)

Powiązane problemy