odd error message in Creator editor



  • Hi all -

    This isn't a Qt problem per se, so I'm not asking about it in the usual forum.

    I'm using Creator as an editor and code browser (but not building or debugging) for an embedded project. My use of the std::string type is giving me an odd error:

    void test()
    {
        std::string s;
        s.clear();
    }
    

    produces "error: member reference base type 'std::string' (aka 'int') is not a structure or union"

    When I compile the code under MSYS2, it's OK, so this is just an annoyance, but I'd be curious as to how to eliminate this error message. My online searches didn't reveal anything helpful.

    Thanks...


  • Moderators

    This pretty much means that the std::string type is unknown. Maybe you're just missing an include for strings in that file? Things like this often go unnoticed as string can easily get pulled from transitive includes or global settings in a large project. Since you're using Creator only for editing it probably doesn't have knowledge of entire project dependencies.

    If you're using clang code model you can click on Tools->C++->Inspect C++ Code Model and check the Header Paths tab to see what it sees.



  • Hi Chris - yeah, that was it...the include file naming in the ESP32 library is a bit unconventional, I guess. I'd been using <string.h> instead, and it worked, but <string> now also works (this is a fairly young library, so they may be renaming files between releases). Thanks...


  • Moderators

    Cool, I'm glad that it worked.
    Just to be clear,<string.h> is the C strings library (has strcpy(), memcmp() and the likes). The C++ equivalent for this is <cstring>.
    None of these have the C++ type std::string, which requires <string>, so the fact that it worked when compiling was not due to the <string.h> include. It just pulled <string> from somewhere.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.