c++ - 相同的声明和类型编译器错误。(xyz* 类型的 arg 与 xyz* 类型的参数不兼容)
问题描述
努力尝试在这里创建一个基本类。
头文件
namespace Ogre
{
class Vector3;
class SceneManager;
class Entity;
class Quaternion;
}
class RayCasting
{
public:
bool RayCastFromPoint(
const Ogre::Vector3 &point,
const Ogre::Vector3 &normal,
Ogre::Vector3 &result,
Ogre::SceneManager& scnMgrRef);
private:
void GetMeshInformation(
Ogre::Entity* entity,
Ogre::Vector3* vertices,
size_t &indexCount,
unsigned long* indices,
const Ogre::Vector3& position,
const Ogre::Quaternion& orient,
const Ogre::Vector3& scale
);
};
源文件
#include "RayCasting.h"
#include <OGRE/OgreMath.h>
#include <OgreRay.h>
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <OgreSceneNode.h>
#include <OgreNode.h>
#include <OgreMath.h>
#include <OgreSubMesh.h>
#include <OgreSubEntity.h>
#include <OgreMesh.h>
#include <OGRE/OgreVector3.h>
bool RayCasting::RayCastFromPoint(
const Ogre::Vector3 & point,
const Ogre::Vector3 & normal,
Ogre::Vector3 & result,
Ogre::SceneManager& scnMgrRef)
{
// get the entity to check
Ogre::Entity *collEntity = static_cast<Ogre::Entity*>(rayQueryResult[index].movable);
// mesh data to retrieve
size_t indexCount;
Ogre::Vector3* vertices = new Ogre::Vector3();
unsigned long* indices;
// get the mesh information
GetMeshInformation(collEntity, vertices, indexCount, indices,
collEntity->getParentNode()->_getDerivedPosition() // Returns a const Vector3
collEntity->getParentNode()->_getDerivedOrientation(), // Returns a const Vector3
collEntity->getParentNode()->_getDerivedScale()); // Returns a const Vector3
...
}
void RayCasting::GetMeshInformation(
Ogre::Entity * entity,
Ogre::Vector3* vertices,
size_t & indexCount,
unsigned long * indices,
const Ogre::Vector3 & position,
const Ogre::Quaternion & orient,
const Ogre::Vector3 & scale)
{
...
}
... 表示不相关的实现细节。
问题 1 RayCasting 中定义的两种方法都抛出 E0147 错误说明
declaration is incompatible with "bool RayCasting::RayCastFromPoint(const Ogre::Vector3 &point, const Ogre::Vector3 &normal, Ogre::Vector3 &result, Ogre::SceneManager &scnMgrRef)" (declared at line 20 of "E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.h") Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 29
`
和
declaration is incompatible with "void RayCasting::GetMeshInformation(Ogre::Entity *entity, Ogre::Vector3 *vertices, size_t &indexCount, unsigned long *indices, const Ogre::Vector3 &position, const Ogre::Quaternion &orient, const Ogre::Vector3 &scale)" (declared at line 27 of "E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.h") Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 140
问题 2 GetMeshInformation(... , vertices, ...) 抛出 E0167 错误,说明
cannot convert to incomplete class "const Ogre::Vector3" Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 91
问题 3 此外,GetMeshInformation(... , ...->_GetDerivedPosition(), ...) 行生成 E0515 错误说明
*"cannot convert to incomplete class const Ogre::Vector3"*, despite the include being present in the Source file. The scale() method also throws this error.
我的问题简单地说是:
什么。在地狱。正在发生。
解决方案
显然,在头文件中前向声明 Ogre::Vectorn 的所有问题都可以通过放弃并在头文件中包含 OgreMath.h 来解决。
推荐阅读
- c++ - 自 C++20 以来是否允许对分配的存储进行指针运算?
- android - setGradientCenter (gradientDrawable.setGradientCenter) 在 GradientDrawable 中不起作用
- vue.js - 在循环中绑定类项
- java - Mockito.when thenReturn 基于输入参数
- reactjs - 对 FieldArray 中的 Formik 字段使用自定义输入时,输入失去焦点
- excel - 将单元格值拆分为多行而不从其他单元格复制数据
- python - 找到熊猫时间序列之间的相关性
- sql - 使用 D365 中另一个表中的字段过滤父数据源
- css - 为什么这个固定元素不水平居中?
- google-cloud-firestore - AngularFire - 如何设置日志记录级别?