gpt4 book ai didi

c++ - 嵌套名称说明符中使用的不完整类型 'TextureLoader'

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

我有这门课

#ifndef WRAPPED_TEXTURE_H
#define WRAPPED_TEXTURE_H

#include <SDL2/SDL.h>
#include "../ui/utils/texture.h"

// color keying - CHROMA KEY!!!!

class WrappedTexture {

public:
WrappedTexture() {
raw_texture = NULL;
width = 0;
height = 0;
bound_renderer = NULL;
}
WrappedTexture(SDL_Renderer* bound_renderer) {
raw_texture = NULL;
width = 0;
height = 0;
this->bound_renderer = bound_renderer;
}
~WrappedTexture() {
printf("Freeing resources!");
free();
}
void free() {
if (raw_texture != NULL) {
SDL_DestroyTexture(raw_texture);
raw_texture = NULL;
width = 0;
height = 0;
}
}
void load_from_file(std::string path) {
free();
TextureLoader::load_texture_chroma(path, bound_renderer, NULL, std::vector<Uint8> { 0, 0xFF, 0xFF}, *this);
}
void render(int x, int y) {
SDL_Rect render_frame = { x, y, width, height };
SDL_RenderCopy(bound_renderer, raw_texture, NULL, &render_frame);
}

int get_width() {
return width;
}
int get_height() {
return height;
}
void set_width_height(int width, int height) {
this->width = width;
this->height = height;
}
void set_raw_texture(SDL_Texture* raw_texture) {
this->raw_texture = raw_texture;
}

private:
SDL_Texture* raw_texture;
int width;
int height;
SDL_Renderer* bound_renderer;
};

#endif

而且我有实用程序类,其中包含对我有用的功能。

#ifndef TEXTURE_H
#define TEXTURE_H

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <vector>

#include "image.h"

#include "../../domain/WrappedTexture.h"

class TextureLoader {
public:
static WrappedTexture *create_wrapped_texture(int width, int height, SDL_Texture* raw, SDL_Renderer* render) {
WrappedTexture* wt = new WrappedTexture(render);
wt->set_width_height(width, height);
wt->set_raw_texture(raw);
return wt;
}
static SDL_Texture* load_texture_chroma(std::string path,
SDL_Renderer* renderer, SDL_Surface* screen_surface,
std::vector<Uint8> pixelColor, WrappedTexture& output) {
int width = -1;
int height = -1;

SDL_Texture* new_texture = NULL;
SDL_Surface* loaded_surface = ImageLoader::load_image(path,
screen_surface);
if (loaded_surface == NULL) {
printf("Unable to load image %s! SDL_image Error: %s\n",
path.c_str(), IMG_GetError());
} else {
SDL_SetColorKey(loaded_surface, SDL_TRUE,
SDL_MapRGB(loaded_surface->format, pixelColor[0],
pixelColor[1], pixelColor[2]));
new_texture = SDL_CreateTextureFromSurface(renderer,
loaded_surface);
if (new_texture == NULL) {
printf("Unable to create texture %s! SDL Error: %s\n",
path.c_str(), SDL_GetError());
} else {
width = loaded_surface->w;
height = loaded_surface->h;
}
SDL_FreeSurface(loaded_surface);
}

if (width != -1 && height != -1 && &output != NULL) {
output = *TextureLoader::create_wrapped_texture(width, height, new_texture, renderer);
}
return new_texture;
}
};

#endif

但我在行 incomplete type 'TextureLoader' used in nested name specifier

中遇到错误
void load_from_file(std::string path) {
free();
TextureLoader::load_texture_chroma(path, bound_renderer, NULL, std::vector<Uint8> { 0, 0xFF, 0xFF}, *this); // error
}

我试图在 WrappedTexture 类中声明 class TextureLoader 并尝试在 TextureLoader 中声明 class WrappedTexture 但它没有'帮助。

有什么问题?

最佳答案

问题可能出在你对类的引用,在它被完全声明之前:

output = *TextureLoader::create_wrapped_texture(width, height, new_texture, renderer);

此时 TextureLoader 类还没有完全声明。尝试将函数定义移至 .cpp 文件。您的所有功能都在 header 中实现是否有原因?

关于c++ - 嵌套名称说明符中使用的不完整类型 'TextureLoader',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31588663/

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