Search code examples
c++templatesfmt

Error C2661 'fmt::v7::print': no overloaded function takes 3 arguments


I am trying to do :

fmt::print(fg(fmt::color::red), "A critical error has occured. consult the logs and fix the issue! {0}", std::endl);

This results in the error message: Error C2661 'fmt::v7::print': no overloaded function takes 3 arguments.

Looking at the official documentation here shows the fmt::print as :

 template <typename S, typename... Args>
void fmt::print(const text_style &ts, const S &format_str, const Args&... args)

which shows the number of arguments shouldn't be an issue, and in fact, it is not. If I replace std::endl with something as random as 1 instead, it compiles and builds just fine! What is wrong here?


Solution

  • std::endl is a template, but template arguments can't be determined in this case, you have to specify them explicitly. e.g.

    fmt::print(fg(fmt::color::red), 
               "A critical error has occured. consult the logs and fix the issue! {0}", 
               std::endl<char, std::char_traits<char>>);
    //                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^