簡體   English   中英

VS2017不支持二進制折疊?

[英]VS2017 does not support binary fold?

為什么以下代碼不編譯?

#include <iostream>

template<typename... Args>
void print_all( Args&&... args )
{
    std::cout << ... << args;
}

int main()
{
    print_all( 1, 2, 3, std::endl );
    return 0;
}

我在使用/ std:c ++ 17的VS2017 15.9.7中遇到以下錯誤

error C2760: syntax error: unexpected token '...', expected 'expression'
error C2660: 'print_all': function does not take 4 arguments

如果刪除std :: endl,第二個錯誤將消失,但是無論使用哪種運算符,任何使用二進制折疊表達式的操作都會出現第一個錯誤。 根據此頁面 ,我的VS版本應支持折疊運算符。

我必須承認,我不知道VS 15.9.7是否支持折疊表達。 但是,您會收到錯誤,因為std::cout << ... << args; 不是fold-expression 正確的語法是

(std::cout << ... << args);

還要注意, std::endl是模板函數,因此您不能簡單地以您的方式傳遞它(因此第二個錯誤)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM