Skip to main content
SZano
Associate III
July 28, 2020
Solved

Compilation error due to "using namespace"

When the designer generates the code for a screen (file "XXXViewBase.cpp") containing a widget with a wildcard, it generates code like this:

txtCount.setPosition(301, 94, 152, 89);
txtCount.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
txtCount.setLinespacing(0);
Unicode::snprintf(txtCountBuffer, TXTCOUNT_SIZE, "%s", touchgfx::TypedText(T_SINGLEUSEID1).getText());
txtCount.setWildcard(txtCountBuffer);
txtCount.setTypedText(touchgfx::TypedText(T_COUNT));

where the use of Unicode::snprintf is unqualified.

It should be touchgfx::Unicode::snprintf, since the file itself doesn't declare "using namespace touchgfx".

The code still compiles just because it implicitly relies on a "using namespace touchgfx" being imported from the auto-generated "XXXPresenter.hpp" (which is included by XXXViewBase.hpp".

The presenter is indeed generated with that statement, but it's editable by the user, and it's bad practice to place a "using namespace" in a header file because it can pollute a lot of other files.

If I remove that line in XXXPresenter.hpp, the compilation of XXXViewBase.cpp fails indeed.

So, the designer should not emit any "using namespace touchgfx" in any auto-generated file, and properly qualify names like the above "Unicode::snprintf".

This topic has been closed for replies.
Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
July 29, 2020

Hello,

Thank you very much for the feedback. We will try to fix this in a later release.

/Alexandre

1 reply

Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
July 29, 2020

Hello,

Thank you very much for the feedback. We will try to fix this in a later release.

/Alexandre