Quote:
Originally Posted by ceanganb
Thanks for the into, Xenakios. C++ is still making sense to me, as I come from a procedural background. This OOP model is a struggle to a 43er
|
Well, to be honest, it is a mess in C++, since objects can be instantiated as values, as heap allocated objects stored in raw pointers, unique pointers or shared pointers etc...Every library/framework of course also has its own rules on what they prefer to use. However, the ability to do it in so many ways also gives flexibility that isn't necessarily available in other languages.
By the way, try to avoid doing manual "delete" calls on heap allocated objects. Manual deletes only leads to misery like double deletions and memory leaks. The example plugin breaks that rule because it would have been a bit contrived to use a smart pointer for the single Window object involved. Proper production code that uses multiple Window instances and creates/destroys them more dynamically should use some other solution. For example the Window instances could be stored in something like :
std::vector<std::shared_ptr<Window>> g_windows;
And then at plugin shutdown they could be destroyed by calling g_windows.clear();
I think I will change the example to do something like that... edit : I changed the window instance to use std::unique_ptr.