对静态整数数组的未定义引用
undefined reference to a static array of integers
我对c++有点陌生,所以我正在制作一个文本RPG之类的东西来测试我所学到的东西。我想让玩家进入他们的三个角色的职业(法师,战士,弓箭手等)。
字符类存储在名为cls[]的静态整型数组中。我更喜欢保持静态,而不是创建这个类的对象,因为几乎游戏中的所有内容都会尝试访问这个类的成员。但出于某种原因,它一直给我的错误信息:未定义的引用' playerVars::cls'。我猜这意味着它找不到数组之类的?我非常感谢你能就这个问题提供任何线索。
intro.h
-----------------------------
#ifndef INTRO_H
#define INTRO_H
#include <iostream>
using namespace std;
class intro
{
public:
intro();
int inint;
void classDecide(int charUsed);
};
#endif
intro.cpp
-----------------------------
#include "intro.h"
#include "playerVars.h"
intro::intro()
{
classDecide(0); //Calls the classDecide function using your first of 3 characters
}
void intro::classDecide(int charUsed)
{
cin >> inint; //Asks for the number of the class that you want
playerVars::setClass(charUsed,inint);
}
playerVars.h
-----------------------------
#ifndef PLAYERVARS_H
#define PLAYERVARS_H
using namespace std;
class playerVars
{
public:
playerVars();
static int cls[3];
static void setClass(int classToSet, int setTo);
};
#endif
playerVars.cpp
-----------------------------
#include "playerVars.h"
playerVars::playerVars()
{
}
void playerVars::setClass(int classToSet, int setTo)
{
cls[classToSet]=setTo; //sets the class of player classToSet to setTo
//undefined reference to `playerVars::cls'
}
添加
int playerVars::cls[3] = {0};
对playerVars.cpp 相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用