I have two classes lib_array_list
that inherit from lib_object
:
class lib_array_list : public lib_object
{
size_t len;
size_t sizememory;
lib_object** objs;//es un array que cada tipo es de lib_object
std::string name;
public:
lib_array_list():len{0},sizememory{4}, objs{new lib_object*[4]}
{
name = "noname";
}
lib_array_list(std::string name)
:name{name},len{0},sizememory{4}, objs{new lib_object*[4]}
{
}
std::string get_array_list_name(){
return name;
}
lib_object& get_array_list_by_name(std::string name){
return get(0);
}
lib_object& get(size_t pos){
return *(objs[pos]);
}
My lib_object class:
class lib_object{
public:
lib_object()
{
}
virtual ~lib_object()
{
}
virtual std::string to_string() const
{
return "x";
}
virtual bool operator ==(const lib_object& obj) const
{
return false;
}
virtual std::string get_class_name()const
{
return "lib_object";
}
};
My class array_list can store objects of the same type, that is arrayists arraylists and in my class lib_array_list I have a get_array_list_by_name
function that at the moment returns a lib_object&
of the first position and what I need is to do a casting to lib_array_list
to be able to operate on it, but I have an error in execution: Aborted (core dumped) My casting is doing so:
lib_array_list r = (lib_array_list&)r.get_array_list_by_name("students");
How should I cast from lib_object
to lib_array_list
?