Skip to content

Add const declarations on implementation files which use them as references

Rodrigo Pedra Brum requested to merge (removed):add-const-references into master

When trying to compile the new Multiple Screens feature released yesterday I got this error on KDE neon:

[ 83%] Building CXX object app/CMakeFiles/latte-dock.dir/lattedockadaptor.cpp.o
[ 84%] Linking CXX executable ../bin/latte-dock
/usr/bin/ld: CMakeFiles/latte-dock.dir/view/clonedview.cpp.o: in function `Latte::ClonedView::translateToClonesOrder(QList<int> const&)':
clonedview.cpp:(.text+0x1aaa): undefined reference to `Latte::ClonedView::ERRORAPPLETID'
collect2: error: ld returned 1 exit status
make[2]: *** [app/CMakeFiles/latte-dock.dir/build.make:2270: bin/latte-dock] Error 1
make[1]: *** [CMakeFiles/Makefile2:1806: app/CMakeFiles/latte-dock.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

After some research I found this StackOverflow answer:

https://stackoverflow.com/a/3026148

Which referenced this FAQ by Bjarne Stroustrup:

https://www.stroustrup.com/bs_faq2.html#in-class

In summary, if a static const is initialized in a class, and later is used as a reference in an implementation file, it should also be declared inside the implementation file. The initialization can live only inside the class.

Maybe the compiler used by @mvourlakos has an optimization to overcome such construct.

In my case by adding these two lines I could compile it on KDE neon (after fixing the first error, compilation failed on a second spot).

Edited by Rodrigo Pedra Brum

Merge request reports

Loading