&引用;无操作员'=';匹配这些操作数;Ogre::Vector3出错
我在初始化一个派生类中的向量时遇到了问题。我使用的是食人魔,我想初始化一个名为CMissile的派生类中的位置 CMissile继承自CWeapon(它有一个纯虚拟函数) CWeapon.h:&引用;无操作员'=';匹配这些操作数;Ogre::Vector3出错,vector,ogre,Vector,Ogre,我在初始化一个派生类中的向量时遇到了问题。我使用的是食人魔,我想初始化一个名为CMissile的派生类中的位置 CMissile继承自CWeapon(它有一个纯虚拟函数) CWeapon.h: #include "CPlayer.h" class CWeapon { protected: CPlayer& myOwner; //Reference to player Ogre::Vector3 myPosition; public: CPlayer getOw
#include "CPlayer.h"
class CWeapon
{
protected:
CPlayer& myOwner; //Reference to player
Ogre::Vector3 myPosition;
public:
CPlayer getOwner();
virtual void doBehaviour() = 0; //Do not add method body for this in CWeapon.cpp, pure virtual function
};
C导弹.h:
#include "CWeapon.h"
class CMissile : CWeapon
{
private:
float myDirection;
public:
CMissile(float, float, float, float, CPlayer&);
};
这里是CMissile.cpp中我的错误所在:
#include "CMissile.h"
CMissile::CMissile(float x, float y, float z, float dir, CPlayer& player)
{
this->myOwner = player;
this->myDirection = dir;
this->myPosition = new Ogre::Vector3(x, y, z); //here is the error, which reads "No operator '=' matches these operands"
}
在CPlayer.h(包括在CWeapon中)中,我有一行:
#include <OgreVector3.h>
#包括
有人知道我做错了什么吗?
新的Ogre::Vector3
将在堆上分配一个新的向量(产生一个Ogre::Vector3*
,一个指向该向量的指针)。您正试图将其分配给myPosition
,它的类型仅为Ogre::Vector3
。这两种类型不兼容
您可能根本不想在这里使用new
,而是:
this->myPosition = Ogre::Vector3(x, y, z);
(将临时向量分配给myPosition
)或通过以下方式直接更新位置:
this->myPosition.x = x;
this->myPosition.y = y;
this->myPosition.z = z;
newogre::Vector3
将在堆上分配一个新的向量(产生一个Ogre::Vector3*
,一个指向该向量的指针)。您正试图将其分配给myPosition
,它的类型仅为Ogre::Vector3
。这两种类型不兼容
您可能根本不想在这里使用new
,而是:
this->myPosition = Ogre::Vector3(x, y, z);
(将临时向量分配给myPosition
)或通过以下方式直接更新位置:
this->myPosition.x = x;
this->myPosition.y = y;
this->myPosition.z = z;
可能是因为食人魔::矢量3我的位置;是否受保护?请注意,此->myOwner=玩家;不会改变割草机所指的内容,而是用“玩家”的内容覆盖它所指的内容(什么都没有?!)。不知道为什么没有初始化它就没有得到编译错误-你遗漏了吗?可能是因为Ogre::Vector3 myPosition;是否受保护?请注意,此->myOwner=玩家;不会改变割草机所指的内容,而是用“玩家”的内容覆盖它所指的内容(什么都没有?!)。不知道为什么你没有初始化它就没有得到编译错误-你忽略了吗?啊,到现在为止,我一直在使用JMonkey一周,而且我习惯于在使用之前必须将向量初始化为新对象。啊,到现在为止,我一直在使用JMonkey一周,而且我习惯于在使用矢量之前将其初始化为新对象。