c++ - 使用 #define 处理 if 语句错误

标签 c++ if-statement typename

我正在尝试创建一个可读函数,它将包含大量重复的 if 语句,使用下面的代码部分。

#define if_identifier(finder, to_find) if((finder = msg.find(to_find)) != std::string npos)

std::string Utility::Decode(const char* buffer, int &playerID) {
    std::string msg(buffer);
    size_t identifier;

    if_identifier(identifier, "P_ID:[") {

    }
}

为什么这段代码会导致 type name is not allowed 错误?

最佳答案

因为那里有垃圾 std::string

尝试将 std::string npos 更改为 std::string::npos

关于c++ - 使用 #define 处理 if 语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32773955/

相关文章:

c++ - 确定模板中模板参数的类型

c++ - 流行软件中关于vcxproject路径的混淆

c++ - 为什么 _umul128 的工作速度比 mul128x64x2 函数的标量代码慢?

C++:如何防止模板专门化指针?

Java 嵌套的 if 语句与 if-else

javascript - 替代 JS/JQuery 中的许多 if/else 语句?

c++ - 为什么模板模板参数不允许 'typename'在参数列表之后

C++多线程程序试图使用删除的函数

if-statement - Neo4j 条件查询

c++ - 为什么必须在哪里放置 “template”和 “typename”关键字?