undefined reference with mingw (template usage)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: undefined reference with mingw (template usage)

  1. #1
    Join Date
    Dec 2010
    Posts
    642

    undefined reference with mingw (template usage)

    Hi there,
    I am wondering why ToStr throws me this error. Could anyone shed some lights on this?
    I am using mingw64 and codeblocks.

    Code:
     
    E:\Jacky\Documents\Code Blocks Projects\PerfectSimX\main.cpp|35|undefined reference to `std::string ToStr<int>(int const&)'|

    Code:
     for (int i = 0; i < NO_CAMS; i++)  {
            std::string filename("E:/Jacky/Documents/Code Blocks Projects/PerfectSimX/Data/Cam");
            std::string restFileName(".cam");
    
            filename += ToStr(i);
            filename += restFileName;
            bool ok = cameras[i].Load(filename);
      }
    
    template <class T>
    std::string ToStr(const T& value)
    {
        std::ostringstream oss;
        oss << value;
        return oss.str();
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,477

    Re: undefined reference with mingw (template usage)

    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2010
    Posts
    642

    Re: undefined reference with mingw (template usage)

    Hello Victor,
    While you are lending me a hand on this one, I am having another problem.
    I am not sure why I got a really strange problem, which should be quite prominent.
    I don't get it.
    Here mingw64 always complains
    E:\Jacky\Documents\Code Blocks Projects\PerfectSimX\objects\..\Objects\Pallet.h|10|error: expected class-name before '{' token|
    Code:
    #pragma once
    
    #include "..\DX9Widget.h"
    #include "..\SkinnedMesh\SkinnedMesh.h"
    #include "Goods.h"
    
    class Pallet : public Goods {  // here, I don't think I have done anything wrong, but keep on getting this error, can't solve it for hours
     public:
        Pallet();
        Pallet(const Pallet& pallet);
        Pallet(const SkinnedMesh& _mesh, const DX9Widget& _Owner);
        virtual ~Pallet() { }
    
        virtual void init() { }
        virtual void OnUpdate(float dt) { }
        virtual void Update(const D3DXMATRIX& mat, float dt){  }
    };
    Code:
    #pragma once
    
    
    #include "..\DX9Widget.h"
    #include "..\SkinnedMesh\SkinnedMesh.h"
    #include "Objects.h"
    
    
    class DX9Widget;
    class SkinnedMesh;
    //class ObjectClass;
    
    
    
    
    class Goods  : public ObjectClass
    {
    public:
    	Goods();
    	Goods(const Goods& goods);
    	Goods(const SkinnedMesh& _mesh, const DX9Widget&  _Owner);
    	virtual ~Goods() { }
    
    	virtual void init() { }
    	virtual void OnUpdate(float dt) { }
    	virtual void Update(const D3DXMATRIX& mat, float dt) { }
    
    
    
    };
    Code:
    #ifndef ObjectClass_H_INCLUDED
    #define ObjectClass_H_INCLUDED
    
    #pragma once
    
    #include "..\DX9Widget.h"
    #include "..\SkinnedMesh\skinnedMesh.h"
    
    class Activity;
    class TruckArrive;
    class SkinnedMesh;
    class DX9Widget;
    
    
    
    
    
    class ObjectClass
    {
    	//friend class InverseKinematics;
    public:
    	ObjectClass();
    	ObjectClass(const SkinnedMesh& _mesh, const DX9Widget& _Owner);
    	virtual ~ObjectClass(void);
    protected:
    
    	virtual void Init();
    	virtual void OnUpdate(float dt) ;
    public:
    	virtual void Update(const D3DXMATRIX& mat, float dt);
    
    
    public:
    	void SetPos(const D3DXVECTOR3& _pos);
    	void SetRot(const D3DXVECTOR3& _rot);
    	void SetScale(const D3DXVECTOR3& _scale) ;
    	void SetScaleCenter(const D3DXVECTOR3& _scale);
    	void SetRotQuat(const D3DXQUATERNION& _quat);
    	void SetRotCenter(const D3DXVECTOR3& _rot);
    
    	void AddToPos(D3DXVECTOR3 &vPos);
    	void AddToScale(D3DXVECTOR3 &vScale);
    	void AddToRot(D3DXVECTOR3 &vRot);
    
    	D3DXVECTOR3 GetPos();
    	D3DXVECTOR3 GetScale();
    	D3DXVECTOR3 GetRot();
    
    	D3DXMATRIX GetWorldMatrix() ;
    
    	SkinnedMesh *GetMesh();
    
    
    	void Draw();
    
    	bool IsVisible();
    	void SetVisible(bool bVisible);
    
    
    
    
    
    
    private:
    	void UpdateMatrices(Bone* f, D3DXMATRIX* m);
    	void SetAnimation(std::string name);
    	void GetAnimations(std::vector<std::string> &animations);
    
    public:
    	SkinnedMesh mesh;
    
    protected:
    	D3DXVECTOR3 m_vPos;
    	D3DXVECTOR3 m_vRot;
    	D3DXVECTOR3 m_vScale;
    	D3DXVECTOR3 m_vScaleCenter;
    	D3DXVECTOR3 m_vRotCenter;
    	D3DXQUATERNION m_quatRot;
    	D3DXMATRIX worldTransform;
    	D3DCAPS9 m_d3dcaps;
    
    	LPD3DXANIMATIONCONTROLLER m_pAnimCtrl;
    
    
    	int m_activeAnimation;
    
        std::vector<std::string> animations;
    
    public:
    	//Activity activity;
    	float energy;
    
    	//*todo DXWidget doesn't have reference to m_vRenderObjectClass
    
    	//DX9Widget parent;
    	//NavMeshTesterTool* m_navMeshTool;
    
    private:
    	bool mVisible;
    
    
    
    };
    
    #endif // ObjectClass_H_INCLUDED
    Last edited by lucky6969b; April 10th, 2014 at 04:51 AM.

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,569

    Re: undefined reference with mingw (template usage)

    Is there a problem with the include file where you define the Goods class?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,477

    Re: undefined reference with mingw (template usage)

    Quote Originally Posted by 2kaud View Post
    Is there a problem with the include file where you define the Goods class?
    Or maybe OP created a circular include sequence?
    Victor Nijegorodov

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

This is a CodeGuru survey question.


Featured


HTML5 Development Center