[英]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”,但是在graphics.cpp中,出现错误。
'graphics' is not a class or namespace name. 'graphics'不是类或名称空间的名称。
it says the location of the error is 它说错误的位置是
graphics::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? 我正在使用Visual Studio 2010,并且在我的代码中,图形被突出显示为类。但是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. 编译器应输出此错误以及给定的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.