What leads to incomplete types? (QGraphicsItem: Source or target has incomplete type)

后端 未结 2 1811
执念已碎
执念已碎 2020-12-19 22:47

I have a custom QGraphicsItem, that (among other things) changed the cursor to an open hand when clicked, using the standard procedure as described in the Qt documentation.

2条回答
  •  误落风尘
    2020-12-19 23:44

    What leads to incomplete types?

    When instead of including the header file which defines a type, you add the line:

    class myclass;
    

    It Forward declares the class myclass which means for compiler it is an Incomplete type. With Incomplete types, One cannot create objects of it or do anything which needs the compiler to know the layout of myclass more than the fact that myclass is just an type. i.e: The compiler does not know what are its members and what its memory layout is. But Since pointers to all objects need just the same memory allocation, You can use the forward declaration when just reffering to an Incomplete type as a pointer.

    So in short, You are forward declaring a class and then performing some operations which need the compiler to know the layout of that class, Since the compiler doesn't know it hence the error.

提交回复
热议问题