I know something about RAII principle which says allocate memory in constructor and deallocate in destructor; But problem is: i wanna use interfaces(classes with only abstract methods, at least one);
And i try to create class-variable of interface type and initialize this variable in cotructor, for example:
class problem_solver
{
private:
path_finder *_path_finder;
area_divider *_divider;
//other methods
};
problem_solver::problem_solver(path_finder *path_finder, area_divider *divider)
: _path_finder(path_finder), _divider(divider)
{
}
interface path_finder:
class path_finder
{
public:
virtual std::vector<std::pair<node *, double>> find_shortest_path(graph const &graph, node *start_node, node *finish_node) = 0;
virtual ~path_finder() = default;
};
And the main problem is there. Because there's no variant to followe RAII-principle, because i need to allocate object and deallocate it manually;
How can i fix it?