[英]C++ - What does “Incomplete type not allowed” error mean, and how can I fix it?
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. 尽管我已经看到很多关于C ++中“不允许输入不完整类型”错误的问题,但我仍然无法弄清楚编译器在向我这样大叫时试图告诉我什么。 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". 我已经能够弄清楚它与#include
-ing头文件有关,但是对于“不完整类型”是什么以及为什么“不允许”它一无所知。 I got the error when trying to inherit from SDL_Window
as such: 尝试从SDL_Window
继承时出现错误:
#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++ - What does “Incomplete type not allowed” error mean C ++-“不允许不完整的类型”错误是什么意思
Incomplete type means that there is no definition for the type SDL_Window
. 类型不完整意味着没有定义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? 我应该怎么做才能阻止它的发生?
Do not attempt to use SDL_Window
as a base class - it is not intended to be used in that way. 不要尝试将SDL_Window
用作基类-不应以这种方式使用它。
SDL_Window
is intended to be used as an opaque pointer. SDL_Window
旨在用作不透明的指针。 Some SDL functions may return you a SDL_Window*
. 某些SDL函数可能会返回SDL_Window*
。 You can store it, and send it as an argument to other SDL functions. 您可以存储它,并将其作为参数发送给其他SDL函数。 That is all it is used for. 这就是它的全部用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.