CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: shared_from_this problem?

  1. #1
    Join Date
    Dec 2010

    shared_from_this problem?

    I've got a class which derives from an abstract class and enable_shared_from_this<>
    however, I have fully implemented the abstract class, but I can't use shared_from_this()
    to get a pointer of itself.

    class AABB : public AStarNode2, public enable_shared_from_this<AABB>
    	// Initialize to an infinitely small AABB.
    	AABB(LPDIRECT3DDEVICE9 pDevice, int x, int z, const D3DXVECTOR3& min, const D3DXVECTOR3& max);
    	AABB(LPDIRECT3DDEVICE9 pDevice, CMesh* pMesh);
    	DWORD GetID() const {
    		return m_id;
    	DWORD Get_ID() {
    		return lastId++;
    	D3DXVECTOR3 GetPos() const { return m_vPos; }
    	D3DXQUATERNION GetRot() const { return m_rot; }
    	D3DXVECTOR3 GetSize() const { return m_size; }
    	float GetRadius() const { return m_radius; }
    	void SetPos(D3DXVECTOR3 pos) { m_vPos = pos; }
    	void SetRot(D3DXQUATERNION rot) { m_rot = rot; }
    	void SetSize(D3DXVECTOR3 size) { m_size = size; }
    	void SetRadius(float radius) { m_radius = radius; }
    	D3DXVECTOR3 GetCenter() {
    		return center();
    	void GetBox(D3DXVECTOR3* vMin, D3DXVECTOR3* vMax);	 
    	void Render();
    	bool Intersect(AABB &b);
    	bool Intersect(Rays &ray);
    	bool Intersect(D3DXVECTOR3 &point);
    	D3DXVECTOR3 GetContactPoint(Rays &ray);
    	vector<D3DXVECTOR3> GetCorners();
    	void setNeighbours(std::vector<boost::shared_ptr<AABB>> neighbours);
    	float getCostEstimate(boost::shared_ptr<AStarNode2> dest, const boost::shared_ptr<PathContext2> pc);
    	// Get generic transitions without getting into the reserved particulars
    	std::vector<boost::shared_ptr<AStarTransition2>> getTransitions(); 
    	int GetX() const { return m_x; }
    	int GetZ() const { return m_z; }
    	D3DXVECTOR3 center()
    		return 0.5f*(minPt + maxPt);
    	static DWORD		lastId;
    	DWORD				m_id;
    	LPDIRECT3DDEVICE9	m_pDevice;
    	D3DXVECTOR3			minPt;
    	D3DXVECTOR3			maxPt;
    	int                 m_x;
    	int                 m_z;
    	D3DXVECTOR3			m_size;
    	float				m_radius;
    	D3DXVECTOR3			mCenter;	
    	D3DXVECTOR3         m_vPos;
    	D3DXQUATERNION      m_rot;	 	 
    	bool                m_bRenderable;
    	CComPtr<ID3DXMesh> mBoundingBoxMesh;
    	std::vector<boost::shared_ptr<AABB>> neighbours;
    	std::vector<boost::shared_ptr<AStarTransition2>> transitions; 
    void AABB::setNeighbours(std::vector<boost::shared_ptr<AABB>> neighbours) {
    	this->neighbours = neighbours;
    	for (std::vector<boost::shared_ptr<AABB>>::iterator it = neighbours.begin(); it != neighbours.end(); it++) {
    		boost::shared_ptr<AABB> neighbour = (*it);
    		boost::shared_ptr<AABB> self = shared_from_this(); <<<<<<<< can't do this
    		boost::shared_ptr<GridTransition2> tran(new GridTransition2(self, neighbour));
    		boost::shared_ptr<GridTransition2> trans(tran);
    Error	1	error C2440: 'initializing' : cannot convert from 'std::shared_ptr<_Ty>' to 'boost::shared_ptr<AABB>'	e:\jacky\documents\visual studio 2013\projects\perfectsim\perfectsim\perfectsim\aabb.cpp	318	1	Perfectsim
    I don't understand why. Could anyone please give me a clue?
    Last edited by lucky6969b; June 26th, 2015 at 03:04 AM.

  2. #2
    Join Date
    Jul 2005

    Re: shared_from_this problem?

    cannot convert from 'std::shared_ptr<_Ty>' to 'boost::shared_ptr<AABB>'
    Either use std::shared_ptr, or boost::enable_shared_from_this.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)