简体   繁体   中英

C++ error expected ' ' or '…' before numeric constant

Noob ask

void setName(const std::string& InkClient) { m_appName = InkClient; }
void setCompactName(const std::string& InkClient) { m_appCompactName = InkClient; }
void setVersion(const std::string& 0.1) { m_appVersion = 0.1 ; }

I dont know how i can fix

void setVersion(const std::string& 0.1) { m_appVersion = 0.1 ; }

const std::string& 0.1

0.1 is actually a constant. A valid variable name is expected. If you don't need that argument for anything else, just remove it (leave brackets empty). If the function must take a parameter of type string by reference, just remove the constant. An argument with no name is not used by the function; however, it allows for dealing with compatibility issues. To keep the parameter usable, try the following:

void setVersion(const std::string& version) {m_appVersion = version;}

where version can be any valid variable name.

I hope this helps! :D

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