Sign in to follow this  

Virtual Functions In Derivation

This topic is 2061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[CODE]
#include "LumPyHeaders.h"
namespace LumPy
{
class MyObject
{
public:
virtual ~MyObject ();
protected:
MyObject ();
public:
static const RTTI TYPE;
virtual const RTTI& GetType () const;
bool IsExactly (const RTTI& rkType) const;
bool IsDerived (const RTTI& rkType) const;
bool IsExactlyTypeOf (const MyObject* pkObject) const;
bool IsDerivedTypeOf (const MyObject* pkObject) const;
void SetName (const String& rkName);
const String& GetName () const;
unsigned int GetID () const;
static unsigned int GetNextID ();
////error////////
[color=#ff0000]virtual MyObject* GetObjectByName (const String& rkName);
virtual void GetAllObjectsByName (const String& rkName,
TArray<MyObject*>& rkObjects);
virtual MyObject* GetObjectByID (unsigned int uiID);[/color]
////error////////
private:
String m_kName;
unsigned int m_uiID;
static unsigned int ms_uiNextID;

//pointer system
public:
void IncrementReferences ();
void DecrementReferences ();
int GetReferences () const;
static THashTable<unsigned int,MyObject*> InUse;
static void PrintInUse (const char* acFilename, const char* acMessage);
private:
int m_iReferences;
};
// static and dynamic type casting
template <class T> T* StaticCast (MyObject* pkObj);
template <class T> const T* StaticCast (const MyObject* pkObj);
template <class T> T* DynamicCast (MyObject* pkObj);
template <class T> const T* DynamicCast (const MyObject* pkObj);
typedef Pointer<MyObject> MyObjectPtr;
#include "MyObject.inl"
}
#endif
[/CODE]
[CODE]
#include "MyRenderer.h"
#include "MyObject.h"
namespace LumPy
{
class MySpatial: public MyObject{
DECLARE_RTTI;
DECLARE_NAME_ID;
public:
// abstract base class
virtual ~MySpatial ();
// parent
MySpatial* GetParent ();
protected:
MySpatial ();
// geometric updates
virtual void UpdateWorldData (double dAppTime);
virtual void UpdateWorldBound () = 0;
void PropagateBoundToRoot ();
// support for hierarchical scene graph
MySpatial* m_pkParent;
public:
// parent access (Node calls this during attach/detach of children)
void SetParent (MySpatial* pkParent);
// renderer needs access to these
void OnDraw (MyRenderer& rkRenderer, bool bNoCull = false);
virtual void Draw (MyRenderer& rkRenderer, bool bNoCull = false) = 0;
};
typedef Pointer<MySpatial> MySpatialPtr;
#include "MySpatial.inl"
}
[/CODE]
MySpatial.obj : error LNK2001: unresolved external symbol "public: virtual class LumPy::MyObject * __thiscall LumPy::MySpatial::GetObjectByName(class LumPy::String const &)" ([email="?GetObjectByName@MySpatial@LumPy@@UAEPAVMyObject@2@ABVString@2@@Z"]?GetObjectByName@MySpatial@LumPy@@UAEPAVMyObject@2@ABVString@2@@Z[/email])
1>MySpatial.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall LumPy::MySpatial::GetAllObjectsByName(class LumPy::String const &,class LumPy::TArray<class LumPy::MyObject *> &)" ([email="?GetAllObjectsByName@MySpatial@LumPy@@UAEXABVString@2@AAV?$TArray@PAVMyObject@LumPy@@@2@@Z"]?GetAllObjectsByName@MySpatial@LumPy@@UAEXABVString@2@AAV?$TArray@PAVMyObject@LumPy@@@2@@Z[/email])
1>MySpatial.obj : error LNK2001: unresolved external symbol "public: virtual class LumPy::MyObject * __thiscall LumPy::MySpatial::GetObjectByID(unsigned int)" ([email="?GetObjectByID@MySpatial@LumPy@@UAEPAVMyObject@2@I@Z"]?GetObjectByID@MySpatial@LumPy@@UAEPAVMyObject@2@I@Z[/email])
1>C:\Users\Jerry\Desktop\LumPy\Debug\LumPy.exe : fatal error LNK1120: 3 unresolved externals

[color=#ff0000]I could solve it by putting the implementation of those 3 functions in MySpatial.cpp, but my question is why do I have to reimplement those three virtual functions? They are not pure virtual, so technically speaking I don't have to implement it in the derived class. [/color]

Share this post


Link to post
Share on other sites

This topic is 2061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this