c++ 在单独的 .cpp 和 .h 文件中创建 class
c++ Creating a class in seperate .cpp and .h files
我正在尝试声明 class "graphics",但在 graphics.cpp 中出现错误。
'graphics' is not a class or namespace name.
它说错误的位置是
graphics::graphics()
我正在使用 Visual Studio 2010,在我的代码中,图形突出显示为 class.. 但它显然不被 graphics.cpp 视为 class ?有谁知道这里的问题是什么?
这是我的代码
//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
然后
//graphics.cpp
#include "graphics.h"
#include "stdafx.h"
graphics::graphics() {}
graphics::~graphics() {}
如果您正在使用 Pre-compiled headers
#include "SDL.h"
#include "graphics.h"
#include "stdafx.h" <<<<< must always be included before anything else
改为
#include "stdafx.h"
#include "SDL.h"
#include "graphics.h"
编译器应将此错误与您给出的错误一起输出。
我正在尝试声明 class "graphics",但在 graphics.cpp 中出现错误。
'graphics' is not a class or namespace name.
它说错误的位置是
graphics::graphics()
我正在使用 Visual Studio 2010,在我的代码中,图形突出显示为 class.. 但它显然不被 graphics.cpp 视为 class ?有谁知道这里的问题是什么?
这是我的代码
//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
然后
//graphics.cpp
#include "graphics.h"
#include "stdafx.h"
graphics::graphics() {}
graphics::~graphics() {}
如果您正在使用 Pre-compiled headers
#include "SDL.h"
#include "graphics.h"
#include "stdafx.h" <<<<< must always be included before anything else
改为
#include "stdafx.h"
#include "SDL.h"
#include "graphics.h"
编译器应将此错误与您给出的错误一起输出。