The details difference in the auto-generated file "Main.cpp" and Component initialization problems

I found that the "MainWindow " class in the inherited juce application class have a “JUCEApplication& app;” member in some demos and others not. What’s the difference?

The “setContentOwned” function in the "MainWindow " class’s constructor, The first Component parameter are some come from the constructor’s parameter and others from the new operator. What’s the difference?

As for the "MainContentComponent " class 's private component member such slider and TextButton, some are apparently initialzied by the use of “new” operator in the "MainContentComponent " class 's constructor but the others don’t do so. How these Component are initialized?

3 4

C++ and Juce allow both ways to create the components (using new and not using it). It’s just not consistent between the different examples and autogenerated pieces of code. Generally these days the recommended approach is to not use pointers and new unless there’s a good reason to. (Good reasons to use them would be if you need polymorphic behavior or want to defer creating the objects in case they are not immediately needed, so you can save memory.)

What is the problem you are having?

1 Like