Reputation: 3462
I have this vector.
vector<CXFileEntity>* menu;// CXFileEntity is class
When i try load an x file to it there is a problem.
Here is my code
menu->at(0)=menu->at(0).LoadXFile(CUtility::GetTheCurrentDirectory()+"\\meshes\\Menu\\background.x", 1, menu->at(0), d3dx->d3ddev);
menu->at(1)=menu->at(1).LoadXFile(CUtility::GetTheCurrentDirectory()+"\\meshes\\Menu\\start.x", 1, menu->at(1), d3dx->d3ddev);
I get these errors
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CXFileEntity *' (or there is no acceptable conversion) c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.cpp 86
Error 2 error C2664: 'CXFileEntity::LoadXFile' : cannot convert parameter 3 from 'CXFileEntity' to 'CXFileEntity *' c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.cpp 87
It seems to be that when I'm assigning a pointer to my vector it doesn't work the error says that CXFileEntity
can't be converted to CXFileEntity*
but i assigned it to be a pointer.
So, I tried to change it to.
menu->at(0)=menu->at(0).LoadXFile(CUtility::GetTheCurrentDirectory()+"\\meshes\\Menu\\background.x", 1, &menu->at(0), d3dx->d3ddev);// added &
but now i got this error
Error 2 error C2664: 'CXFileEntity::LoadXFile' : cannot convert parameter 3 from 'CXFileEntity' to 'CXFileEntity *' c:\users\owner\documents\visual studio 2010\projects\monopoly\monopoly\window.cpp 87
I'm so lost with this one..
EDIT 2:
Here is the CXFileEntity class
#pragma once
#include "stdafx.h"
/*
This class represents an x file animation
It loads the .x file and carries out the animation update and rendering
*/
class CXFileEntity
{
private:
LPDIRECT3DDEVICE9 m_d3dDevice; // note: a pointer copy (not a good idea but for simplicities sake)
// Direct3D objects required for animation
LPD3DXFRAME m_frameRoot;
LPD3DXANIMATIONCONTROLLER m_animController;
D3DXMESHCONTAINER_EXTENDED* m_firstMesh;
// Bone data
D3DXMATRIX *m_boneMatrices;
UINT m_maxBones;
// Animation variables
unsigned int m_currentAnimationSet;
unsigned int m_numAnimationSets;
unsigned int m_currentTrack;
float m_currentTime;
float m_speedAdjust;
// Bounding sphere (for camera placement)
D3DXVECTOR3 m_sphereCentre;
float m_sphereRadius;
std::string m_filename;
void UpdateFrameMatrices(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix);
void UpdateSkinnedMesh(const D3DXFRAME *frameBase);
void DrawFrame(LPD3DXFRAME frame) const;
void DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const;
void SetupBoneMatrices(D3DXFRAME_EXTENDED *pFrame/*, LPD3DXMATRIX pParentMatrix*/);
bool Load(const std::string &filename);
public:
CXFileEntity(LPDIRECT3DDEVICE9 d3dDevice);
~CXFileEntity(void);
mutable D3DXMATRIX m_combinedMat, * s;
void CreateRay();
mutable LPD3DXMESH pDrawMesh;
bool draw;
float distanceToCollision;
BOOL hasHit;
CXFileEntity* LoadXFile(const std::string &filename,int startAnimation, CXFileEntity *menus, LPDIRECT3DDEVICE9 d3ddev);
void FrameMove(float elapsedTime,const D3DXMATRIX *matWorld);
void Render() const;
void SetAnimationSet(unsigned int index);
void SetComb(LPDIRECT3DDEVICE9 d3dDevice, D3DXMATRIX world);
float m_fHitDist;
CXFileEntity *m_pChild;
CXFileEntity *m_pSibling;
void NextAnimation();
void AnimateFaster();
void AnimateSlower();
D3DXVECTOR3 GetInitialCameraPosition() const;
unsigned int GetCurrentAnimationSet() const {return m_currentAnimationSet;}
std::string GetAnimationSetName(unsigned int index);
std::string GetFilename() const {return m_filename;}
};
Upvotes: 1
Views: 996
Reputation: 892
LoadXFile()
seems to be returning a pointer, ie. CXFileEntity *
while the vector only accepts objects of CXFileEntity.
I don't understand your design. You have instances of CXFileEntity
in your std::vector
. Then you access those instances and call LoadXFile()
on them... which return pointers to CXFileEntity
, which you're trying to store back inside the std::vector
?
Following your own flow,
You need to use the dereference operator *
to obtain access to the actual object that the pointer points to.
menu->at(0)=*(menu->at(0).LoadXFile(CUtility::GetTheCurrentDirectory()+
"\\meshes\\Menu\\background.x", 1, &(menu->at(0)), d3dx->d3ddev));
The second error says that you need to pass in a pointer to a CXFileEntity
, as you guessed. The problem was operator precedence, so you need to use appropriate parentheses.
Upvotes: 1