There is such code:
int main() { unique_ptr<ProjectModel> model = unique_ptr<ProjectModel>(new ProjectModel(2)); unique_ptr<ProjectControl> control = unique_ptr<ProjectControl>(new ProjectControl(*model)); unique_ptr<ProjectView> view = unique_ptr<ProjectView>(new ProjectView(*control)); return 0; }
When closing the program, an exception crashes: read access violation What could be the problem? I read that in main you always need to catch exceptions, is it true and how correct is it?
I fixed an exception pointing to the destructor model, but now it throws a general exception to read access violation. I have the following code:
class ProjectView { public: ProjectView::ProjectView(ProjectControl& control) : m_control(&control) {} private: const std::shared_ptr<ProjectControl> m_control; } class ProjectControl { public: ProjectControl::ProjectControl(ProjectModel& model) : m_model(&model) {} private: const std::shared_ptr<ProjectModel> m_model; }
shared_ptr
not the best way, although probably the easiest. - αλεχολυτshared_ptr
. Becauseunique_ptr
doesn’t fit here, storing a reference to an object thatunique_ptr
ownsunique_ptr
is a gross mistake. - Pavel Mayorov