编译说成员是未宣布的,他们显然不是。 (SDL)

时间:2015-02-12 04:48:30

标签: c++ class sdl

一切都很好,直到我决定重新开始我的项目并从头开始构建一个新框架。编译器告诉我,我的Game类中声明的所有成员都是未声明的,即使它们就在那里。即使我在类中声明一个简单的int,它也不会在Game.cpp中看到它。我没有看到一些简单的东西。

Game.h

#ifndef __Game__
#define __Game__

#pragma once

#include "SDL.h"

class Game
{
public:
    Game();
    ~Game();

int Init(const char* title, int xPos, int yPos, int width, int height, int flags);

private:
SDL_Window* MainWindow;
SDL_Renderer* MainRenderer;
int CurrentFrame;
bool Running;
};

#endif

Game.cpp

#include "Game.h"
#include <iostream>
using namespace std;


Game::Game()
{

}


Game::~Game()
{

}

int Init(const char* title, int xPos, int yPos, int width, int height, int  flags)
{
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
cout << "SDL init success\n";

 MainWindow = SDL_CreateWindow(title, xPos, yPos, width, height, flags);

if(MainWindow != 0) 
    {
    cout << "window creation success\n";
    MainRenderer = SDL_CreateRenderer(MainWindow, -1, 0);

        if(MainRenderer != 0) 
        {
        cout << "renderer creation success\n";
        SDL_SetRenderDrawColor(MainRenderer, 255,255,255,255);
        }
        else
        {
        cout << "renderer init fail\n";
        return false; 
        }
}
else
{
cout << "window init fail\n";
return false; 
}

}
else
{
cout << "SDL init fail\n";
return false; 
}
    cout << "init success\n";


return 0;


}

这是编译日志:

>------ Build started: Project: idcdc, Configuration: Debug Win32 ------
1>  Game.cpp
1>c:\users\cole\documents\visual studio      2010\projects\idcdc\idcdc\game.cpp(23): error C2065: 'MainWindow' : undeclared   identifier
1>c:\users\cole\documents\visual studio    2010\projects\idcdc\idcdc\game.cpp(25): error C2065: 'MainWindow' : undeclared  identifier
1>c:\users\cole\documents\visual studio   2010\projects\idcdc\idcdc\game.cpp(28): error C2065: 'MainRenderer' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(28): error C2065: 'MainWindow' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(30): error C2065: 'MainRenderer' : undeclared  identifier
1>c:\users\cole\documents\visual studio  2010\projects\idcdc\idcdc\game.cpp(33): error C2065: 'MainRenderer' : undeclared  identifier
1>  Generating Code...
1>  Compiling...
1>  Main.cpp
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

听起来应该有一个简单的答案,但我可耻地不知道这里发生了什么,谢谢你。

1 个答案:

答案 0 :(得分:3)

根据您对函数Init的定义,它不是类Game的成员。改为

int Game::Init(const char* title, int xPos, int yPos, int width, int height, int flags)