Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Object 将对象作为参数传递给另一个对象visual c++; 我试图通过C++中的引用传递一个对象。我发现以下错误:_Object_Visual C++_Parameters_Sdl_Pass By Reference - Fatal编程技术网

Object 将对象作为参数传递给另一个对象visual c++; 我试图通过C++中的引用传递一个对象。我发现以下错误:

Object 将对象作为参数传递给另一个对象visual c++; 我试图通过C++中的引用传递一个对象。我发现以下错误:,object,visual-c++,parameters,sdl,pass-by-reference,Object,Visual C++,Parameters,Sdl,Pass By Reference,错误1错误C2061:语法错误:标识符“公共”图形。h 6 1 SDLGameDev 错误2错误C2511:'void Graphics::CreateWindow(Common&'):在'Graphics'4 1 SDLGameDev中找不到重载的成员函数 我找到了关于这方面的答案,但没有任何涉及如何做到这一点的答案: object1.someFunction(object2); 这是我的密码: //普通的 #ifndef COMMON_H #define COMMON_H #include

错误1错误C2061:语法错误:标识符“公共”图形。h 6 1 SDLGameDev

错误2错误C2511:'void Graphics::CreateWindow(Common&'):在'Graphics'4 1 SDLGameDev中找不到重载的成员函数

我找到了关于这方面的答案,但没有任何涉及如何做到这一点的答案:

object1.someFunction(object2);
这是我的密码:

//普通的

#ifndef COMMON_H
#define COMMON_H
#include "SDL.h"
#include "iostream"

class Common{
public:
    void Init();
    bool GetGameRunState(){ return GameRunState; }
    void SetGameRunState(bool x){ GameRunState = x; }
private:
    bool GameRunState;
};

#endif 
//Commmon.cpp

#include "Common.h"

void Common::Init()
{
    if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
    {
        SetGameRunState(true);
    }
    else
    {
        SetGameRunState(false);
    }
}
//图形.h

#ifndef GRAPHICS_H
#define GRAPHICS_H

class Graphics{
public:
    void CreateWindow(Common & co);
};

#endif
//Graphics.cpp

#include "Graphics.h"
#include "Common.h"
void Graphics::CreateWindow(Common & co)
{
    if (co.GetGameRunState() == true)
    {
        std::cout << "TEST for CreateWindow()\n";
    }
}
#包括“Graphics.h”
#包括“Common.h”
void Graphics::CreateWindow(通用和公司)
{
if(co.GetGameRunState()==true)
{

std::cout文件Graphics.h中没有包含Common.h,因此它不知道该类

#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "Common.h"  // You need this line

class Graphics {
public:
    void CreateWindow(Common & co);
};

#endif

我建议使用单例,并将sdl的初始化、渲染器和窗口的创建等都放在一个类中。您的问题已经得到了回答。

哇,这太痛苦了。非常感谢Zammald!
#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "Common.h"  // You need this line

class Graphics {
public:
    void CreateWindow(Common & co);
};

#endif