如下代码为啥在VS2019里编译没问题,但在GCC上编译报错?


template<typename IgnoreFuncT = std::function<bool(const std::string&, class...args)> >
std::ostream& writeString(
    std::ostream& os, const std::string& input, IgnoreFuncT ignoreFunc)
{
    if (!ignoreFunc(input)) {
        os << input;
    }
    return os;
}
bool checkFunc(const std::string& input) {
    static const std::string splitChar(",");
    return (input.find(splitChar) == std::string::npos);
}

TEST(aaaaa, aaaa2222)
{
    std::stringstream oss;
    const std::string str("+aa");
    writeString(oss, str, std::bind(&checkFunc, str));
    EXPECT_EQ(std::string("\"\t+aa\""), oss.str());
}

是不是缺少头文件

不是,提示错误如下
error: template argument 1 is invalid
template<typename IgnoreFuncT = std::function<bool(const std::string&, class...args)> >

std::function<bool(const std::string&, class...args)>这个地方写错了,std::function的模板参数必须是具体的类型。你可以改为std::function<bool(const std::string&)>