Cole-Peterson
Cole-Peterson

Reputation: 49

Compiler says members are undeclared, they are clearly not. (SDL)

All was fine until I decided to start over my project and build a new framework from scratch. The compiler is telling me all the members declared in my Game class are undeclared even though they are right there. Even if I declare a simple int in the class it will not see it in Game.cpp. There's got be something simple I am not seeing.

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;


}

Here is the compile log:

>------ 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 ==========

It sounds like there should be a simple answer but i shamefully do not know what is happening here thank you.

Upvotes: 0

Views: 257

Answers (1)

Martin G
Martin G

Reputation: 18109

According to your definition of function Init it is not a member of class Game. Change to

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

Upvotes: 3

Related Questions