0

to sum up my problem, lets say I have this:

class Base {};

class Derived_one : public Base {
private:
    Polymorphic_vector arr;
public:
    const Polymorphic_vector& get_arr() const{
        return this->arr;
    }
};

class Derived_two : public Base {};

//Polymorphic_vector.hpp
#include "Base.hpp"
class Polymorphic_vector : public std::vector<Base*> { //some overrided f-ns };

class Foo {
    //here i want to have the ability of sth like this
    //this->at(int position)->get_arr();
    //i.e. call get_arr()
};
//end of Polymorphic_vector.hpp

In the polymorphic vector I have pointers to objects of type Derived_one and Derived_two. I want to call get_arr() in Foo. But in order to be able to do that, I should have it as a virtual f-n in class 'Base' and override it in the derived ones. But, since those classes are in different .hpp files, I would have to include "Polymorphic_vector.hpp" in 'Base', because the f-n get_arr() return a value of type Polymorphic_vector. But I already have 'Base' included in 'Polymorphic_vector'. So yeah, thats it :D I would love to receive some feedback about how to solve that problem, thank you.

  • You can simply forward declare `Base` in Polymorphic_vector.hpp instead of including Base.h –  May 19 '20 at 17:24
  • I tried it, but if I do it one way, i get a message telling me using this-> is not possible, and if I do it the other way, the mesage is "use_of_undefined_type". – user13575922 May 19 '20 at 17:31

1 Answers1

0

Turns out forward declaration is the only way to go in this case. Here it didnt work cause the actual classes I have are ~30 and the inheritance is far more complex, but with a little bit of moving around with the functions I managed to solve my problem. Generally though, this could be of help to someone : c++ header files including each other mutually