Cppcheck "Class MainWindow ... argument that is not explicit"


not a big deal but ....

in Source/Main.cpp cppcheck says:

    Class 'MainWindow' has a constructor with 1 argument that is not explicit.

warning can be removed either by specifying "explicit":

    explicit MainWindow (String name) : DocumentWindow(name,

or removing the 'name'  param

MainWindow () : DocumentWindow("a-name",

so this is not a problem regarding Main.cpp which the jucer does not clobber but as for Component classes cppcheck reports this warning for any single-argument constructor if not declared 'explicit' - as far as i can tell the jucer does not allow this to be specified - yes?


It's generally good practice to add 'explicit' to constructors like that, but unlikely ever to cause problems in component classes.

A more useful criticism of that line of code would be that you should always use references rather than pointers wherever possible. This is a really important habit to learn, especially in larger projects, because it helps to make it clear about lifetimes and ownership of objects. Presumably your app object will outlive this window and will never change, so it should almost certainly be passed as a reference. 


yea sry that was me - i was just editing this post as you answered it - MyCoolApplication is the main JUCEApplication -the original param is MainWindow(String name)

im not so much concerned with errors but that i just dont like seeing warnings