gpt4 book ai didi

c++ - 对类的私有(private)函数的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 02:52:31 25 4
gpt4 key购买 nike

因此,我正在调试一些我拼凑在一起的可怕代码,最后(希望如此)找到我的 scene_manager.cpp 中的最后一个错误,但我似乎不明白为什么我会得到它。错误

|22|undefined reference to `scene_manager::applySurface(int, int, SDL_Surface*, SDL_Surface*)'|

scene_manager.cpp

#include "scene_manager.h"

scene_manager::scene_manager(screen_manager* s){
screen = s;
}

void scene_manager::add_object(object_manager* obj){
if(game_objects.find(obj->get_name()) != game_objects.end()){
game_objects[obj->get_name()] = obj;
}
}

void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination){
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}

int scene_manager::render(){
for(iter = game_objects.begin(); iter != game_objects.end();iter++){
applySurface(game_objects.at(iter->first)->get_x(),game_objects.at(iter->first)->get_y(),game_objects.at(iter->first)->get_sprite(),screen->get_screen());
}
if(SDL_Flip(screen->get_screen()) == -1){
return 1;
}
return 0;
}

scene_manager.h

#ifndef SCENE_MANAGER_H
#define SCENE_MANAGER_H
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "object_manager.h"
#include "screen_manager.h"
#include <map>
#include <string>

class scene_manager{
public:
scene_manager();
scene_manager(screen_manager* s);
void add_object(object_manager* obj);
int render();
private:
std::map<std::string,object_manager*>game_objects;
std::map<std::string,object_manager*>::iterator iter;
screen_manager* screen;
void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
};
#endif

最佳答案

看来,这一行

void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination){

想读书

void scene_manager::applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination){

关于c++ - 对类的私有(private)函数的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18808879/

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