简体   繁体   中英

Cast variadic template type to void, expected ')' before

In my code, I use variadic template functions for the logging mechanism. If DEBUG macro is defined, a message is printed; if DEBUG is not defined, then it should print nothing.

My code:

#ifdef DEBUG
    inline void LOG_CHAT(){ }

    template<typename First, typename ...Rest>
    void LOG_CHAT(First && first, Rest && ...rest){
        std::cout << std::forward<First>(first);
        LOG_CHAT(std::forward<Rest>(rest)...);
    }

#else

    template<typename ...Rest>
    void LOG_CHAT(Rest && ...rest){ 
        (void)(rest...);
    }

#endif

I would leave the function definition empty, but I do not want to get "unused parameter" compiler warning. Therefore, parameter(s) are cast to void to get rid of the compiler warning. However, casting is causing another error that is reproduced below.

error: expected ')' before 'rest' UNUSED(...rest);

note: in definition of macro 'UNUSED' #define UNUSED(x) (void)(x)

So, my main goal is getting rid of compiler warning, either by casting to void or using any other method. But I would be happier if I'd be able to cast it to void .

您可以在没有参数名称的LOG_CHAT下发布LOG_CHAT ,这将禁止警告。

void LOG_CHAT(Rest && ...)

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