简体   繁体   中英

c++ Creating a class in seperate .cpp and .h files

I am trying to declare the class "graphics" but in graphics.cpp, I get the error.

'graphics' is not a class or namespace name.

it says the location of the error is

graphics::graphics()

I am using Visual Studio 2010, and in my code, graphics is highlighted as a class.. yet it is apparently not considered a class by graphics.cpp? Does anyone know what the problem is here?

Here is my code

//graphics.h
#ifndef GRAPHICS_H
#define GRAPHICS_H

struct SDL_Window;
struct SDL_Renderer;

class graphics
{
public:
     graphics();
     ~graphics();
private:
     SDL_Window* _window;
     SDL_Renderer* _renderer;
};

#endif

and then

//graphics.cpp
#include "graphics.h"
#include "stdafx.h"

graphics::graphics() {}
graphics::~graphics() {}

If you are using Pre-compiled headers

#include "SDL.h"
#include "graphics.h"
#include "stdafx.h" <<<<< must always be included before anything else

Change to

#include "stdafx.h"
#include "SDL.h"
#include "graphics.h"

The compiler should output this error along with your given error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM