gpt4 book ai didi

c++ - 传递给函数的字符串是 undefined symbol

转载 作者:行者123 更新时间:2023-11-27 23:37:26 25 4
gpt4 key购买 nike

<分区>

我创建了一个包含 stringbool 对的映射的单例,用于在键盘上按下某个键时进行存储。

我有以下头文件:

#pragma once

#include <unordered_map>
#include <iostream>
#include <string>

using namespace std;

// Singleton service that stores keypresses during frame

class KeyboardService
{
private:
static KeyboardService* instance;

unordered_map<string, bool> keys =
{
{"up", 0},
{"down", 0},
{"left", 0},
{"right", 0},
{"one", 0},
{"two", 0},
{"three", 0},
{"d", 0}
};

KeyboardService(){};

public:
static KeyboardService* getInstance();

bool isPressed(string input);
void pressKey(string input);
void unpressKey(string input);

};

和实现:

#pragma once

#include "keyboard_service.hpp"

KeyboardService* KeyboardService::instance = 0;

unordered_map<string, bool> keys;

KeyboardService* KeyboardService::getInstance()
{
if(!instance)
{
instance = new KeyboardService;
}
return instance;
}

bool isPressed(string input)
{
return keys[input];
}

void pressKey(string input)
{
keys[input] = 1;
}

void unpressKey(string input)
{
keys[input] = 0;
}

当我尝试使用这些函数时,出现错误:

"KeyboardService::isPressed(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
UserInputSystem::update(float) in user_input_system.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com