[英]C++ Undefined reference to Holder::menus (Struct)
Ok, so I have a struct defined as thus: 好的,因此我定义了一个结构,如下所示:
#ifndef __STRUCTS_H__
#define __STRUCTS_H__
struct counts {
int views = 0;
int inits = 0;
};
#endif
I have a class that is going to have entirely static methods and variables that are accesable by all classes. 我有一个类,它将具有所有类都可以使用的完全静态的方法和变量。
#ifndef __HOLDER_H__
#define __HOLDER_H__
#include "Structs.h"
class Holder
{
public:
static counts menus;
Holder() {
menus = counts();
}
};
#endif
And so I tried to acess this method and the compiler spits out the error "Undefined reference to Holder::menus" 因此,我尝试使用此方法,并且编译器吐出错误“对Holder :: menus的未定义引用”
Here is the segment that triggers this (HelloWorldScene.cpp) 这是触发此操作的段(HelloWorldScene.cpp)
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "Holder.h"
#include "Structs.h"
USING_NS_CC;
HelloWorld::HelloWorld(void)
{
//Constructor
Debug::crashLog("**__Menu Deinit__**");
//SUDO Missing stuff
Holder::menus.inits -= 1;
}
Why is it having issues? 为什么会有问题?
in your Holder
implementation file you need this: 在您的
Holder
实施文件中,您需要这样做:
counts Holder::menus;
if you don't have Holder.cpp
file, (and you don't want one) you can put it directly into in HelloWorldScene.cpp
. 如果您没有
Holder.cpp
文件(并且您不需要),则可以将其直接放入HelloWorldScene.cpp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.