首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编译器说成员是未声明的,显然不是。(SDL)

编译器说成员是未声明的,显然不是。(SDL)
EN

Stack Overflow用户
提问于 2015-02-12 04:48:29
回答 1查看 235关注 0票数 0

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

Game.h

代码语言:javascript
运行
复制
#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

代码语言:javascript
运行
复制
#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;


}

以下是编译日志:

代码语言:javascript
运行
复制
>------ 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 ==========

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-12 04:52:14

根据函数Init的定义,它不是类Game的成员。变到

代码语言:javascript
运行
复制
int Game::Init(const char* title, int xPos, int yPos, int width, int height, int flags)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28469494

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档