cancel
Showing results for 
Search instead for 
Did you mean: 

Compilation error due to "using namespace"

SZano
Associate III

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".

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

Hello,

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

/Alexandre

View solution in original post

1 REPLY 1
Alexandre RENOUX
Principal

Hello,

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

/Alexandre