C++ - 什么是“不允许不完整的类型"?错误的意思,我该如何解决? [英] C++ - What does "Incomplete type not allowed" error mean, and how can I fix it?

查看:66
本文介绍了C++ - 什么是“不允许不完整的类型"?错误的意思,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我在 C++ 中看到了很多关于不允许的不完整类型"错误的问题,但我仍然无法弄清楚编译器在像这样对我尖叫时试图告诉我什么.我已经能够拼凑起来,它与 #include-ing 头文件有关,但我对不完整类型"是什么以及为什么不允许"一无所知.尝试从 SDL_Window 继承时出现错误:

Although I've seen many questions referring to the "Incomplete type not allowed" error in C++, I still cannot figure out what the compiler is trying to tell me when it screams at me like this. I've been able to piece together that it has something to do with #include-ing header files, but I am clueless as to what an "incomplete type" is and why it is "not allowed". I got the error when trying to inherit from SDL_Window as such:

#pragma once
#include "SDL.h"

class Window : public SDL_Window
{
public:
  Window();
  ~Window();
};

有人可以向我解释这个错误是什么意思,如何(通常)修复它,就我而言,我应该怎么做才能阻止它发生?

Could someone please explain to me what the error means, how to (generally) fix it, and, in my case, what I should do to stop it from happening?

推荐答案

C++ - Incomplete type not allowed"错误是什么意思

C++ - What does "Incomplete type not allowed" error mean

不完整类型意味着没有类型SDL_Window的定义.

Incomplete type means that there is no definition for the type SDL_Window.

该错误意味着该类型不完整,并且在该上下文中不允许使用不完整的类型.在这种特殊情况下:不完整的类型不能用作基类.

The error means that the type is incomplete, and that an incomplete type wasn't allowed in that context. In this particular case: an incomplete type cannot be used as a base class.

我应该怎么做才能阻止它发生?

what I should do to stop it from happening?

不要尝试使用 SDL_Window 作为基类 - 它不打算以这种方式使用.

Do not attempt to use SDL_Window as a base class - it is not intended to be used in that way.

SDL_Window 旨在用作不透明指针.某些 SDL 函数可能会返回一个 SDL_Window*.您可以存储它,并将其作为参数发送给其他 SDL 函数.这就是它的全部用途.

SDL_Window is intended to be used as an opaque pointer. Some SDL functions may return you a SDL_Window*. You can store it, and send it as an argument to other SDL functions. That is all it is used for.

这篇关于C++ - 什么是“不允许不完整的类型"?错误的意思,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆