Hello!
Im having a problem with the following code structure. The code compiles without problems but when i start the program i get an "exception: __non_rtti_object at memory location...". In the constructor of the model-class i still can get the object information of the node-class through the base pointer. Once the construction of the model-object is completed the class information somehow got lost. I would be very grateful if somebody could point the problem out. Thanks!
#ifndef PATH_H
#define PATH_H
template<class T>
class Path
{
private:
T* lastPathComponent;
Path(const Path<T>&);
Path<T>& operator=(const Path<T>& rv);
public:
Path(const T& singlePath) { lastPathComponent = &singlePath; }
~Path(void) {}
T& getLastPathComponent(void) const
{
return *lastPathComponent;
}
};
#endif //PATH_H
#ifndef BASENODE_H
#define BASENODE_H
class BaseNode
{
private:
BaseNode(const BaseNode&);
BaseNode& operator=(const BaseNode& rv);
public:
BaseNode(void) {};
virtual ~BaseNode(void) {};
};
#endif //BASENODE_H
#ifndef NODE_H
#define NODE_H
#include <string>
#include "BaseNode.h"
#include "Path.h"
class Node : public BaseNode
{
private:
std::string name;
Node(const Node&);
Node& operator=(const Node& rv);
public:
Node(void) { name = ""; }
~Node(void) {}
std::string getName(void) const { return name; }
void setName(const std::string& name) { this->name = name; }
};
#endif //NODE_H
#ifndef MODEL_H
#define MODEL_H
#include "Path.h"
#include "BaseNode.h"
class Model
{
private:
TreePath<BaseNode* const>* dataNodePath;
Model(const Model&);
Model& operator=(const Model& rv);
public:
Model(BaseNode* node)
{
dataNodePath = new TreePath<BaseNode* const>(node);
std::cout << typeid(*getDataNodePath().getLastPathComponent()).name() << std::endl; // valid information
}
virtual ~Model(void)
{
delete dataNodePath; dataNodePath = NULL;
}
const TreePath<BaseNode* const>& getDataNodePath(void) const
{
return *dataNodePath;
}
};
#endif //MODEL_H
int main( )
{
Node* x = new Node();
x->setName("this is a node");
Model* m = new Model(x);
cout << typeid(*m->getDataNodePath().getLastPathComponent()).name() << endl; // exception: __non_rtti_object at memory location...
delete m;
delete x;
}