【发布时间】:2017-11-01 04:53:18
【问题描述】:
我遇到了循环声明的问题,但到目前为止找到的所有解决方案都不能直接解决问题。
这里有一些代码:
Transformable.h
#pragma once
#include "TransformMatrix.h"
class Transformable {
public:
TransformMatrix Transform;
virtual void transform_callback();
};
TransformMatrix.h
#pragma once
#include "Transformable.h"
class Transformable;
class TransformMatrix {
private:
Transformable *callback_object;
public:
TransformMatrix();
TransformMatrix(Transformable *cb_object);
Transforms.h
#pragma once
#include "Transformable.h"
#include "TransformMatrix.h"
啊.h
class A: public Transformable {
public:
A();
/* We want a callback */
TransformMatrix Transform = TransformMatrix(this);
我有一个实现基类的类,并使用一个特殊的头文件,所以我不必每次都包含两个文件。但我得到的错误是:
Transformable.h(7):错误 C3646:“转换”:未知覆盖
Transformable.h(7):错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int。
【问题讨论】:
-
您应该从 TransformMatrix.h 文件中删除 #include "Transformable.h" 指令。
-
我也试过了,我最终得到:
1>TransformMatrix.cpp(141): error C2027: use of undefined type 'Transformable' 1>TransformMatrix.h(8): note: see declaration of 'Transformable' 1>TransformMatrix.cpp(141): error C2227: left of '->transform_callback' must point to class/struct/union/generic type -
听起来您现在需要将#include "Transformable.h" 添加到您的 TransformMatrix.cpp 文件中?
-
在 TransformMatrix.cpp 中添加
#include "Transformable.h"。 -
好吧,修复了它,但我还必须将 Transformable.h 中的虚拟 void 更改为常规 void,因为即使我使用类型转换,编译器也不知道cast 尚未实施。谢谢!