Jump to content
  • Advertisement
Sign in to follow this  

Virtual Functions In Derivation

This topic is 2342 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

#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);
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!