首页 > 解决方案 > 相同的声明和类型编译器错误。(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.

我的问题简单地说是:

什么。在地狱。正在发生。

标签: c++methods

解决方案


显然,在头文件中前向声明 Ogre::Vectorn 的所有问题都可以通过放弃并在头文件中包含 OgreMath.h 来解决。


推荐阅读