Sign in to follow this  

Virtual Functions In Derivation

Recommended Posts

#include "LumPyHeaders.h"
namespace LumPy
class MyObject
virtual ~MyObject ();
MyObject ();
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 ();
[color=#ff0000]virtual MyObject* GetObjectByName (const String& rkName);
virtual void GetAllObjectsByName (const String& rkName,
TArray<MyObject*>& rkObjects);
virtual MyObject* GetObjectByID (unsigned int uiID);[/color]
String m_kName;
unsigned int m_uiID;
static unsigned int ms_uiNextID;

//pointer system
void IncrementReferences ();
void DecrementReferences ();
int GetReferences () const;
static THashTable<unsigned int,MyObject*> InUse;
static void PrintInUse (const char* acFilename, const char* acMessage);
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"
#include "MyRenderer.h"
#include "MyObject.h"
namespace LumPy
class MySpatial: public MyObject{
// abstract base class
virtual ~MySpatial ();
// parent
MySpatial* GetParent ();
MySpatial ();
// geometric updates
virtual void UpdateWorldData (double dAppTime);
virtual void UpdateWorldBound () = 0;
void PropagateBoundToRoot ();
// support for hierarchical scene graph
MySpatial* m_pkParent;
// 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"
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

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