简体   繁体   中英

Get error on using std::string::npos

On C++, I get following error message:

error: ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ is not a namespace or unscoped enum

on this line:

  using std::string::npos;

What's wrong with it? I'm using g++ with 2017 standard (-std=c++17)

I included < string > header.

Read again the error.

It tells you: "unless your are trying to alias a namespace or an unscoped enum, I will cowardly refuse to have anything to do with this using clause".

That is to say: don't try to define aliases for static constants and you'll be fine.

The cited reference says:

Using-declarations can be used to introduce namespace members into other namespaces and block scopes, or to introduce base class members into derived class definitions.

There's no mention about "introducing static constant members".

'npos' is not a namespace nor a enum. It's a static constant member.

using std; means "After this command I can write string instead of std::string "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM