久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

最令人頭疼的解析混亂

Most vexing parse confusion(最令人頭疼的解析混亂)
本文介紹了最令人頭疼的解析混亂的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在學習 C++11,我偶然發現了統一初始化程序.

I'm studying C++11 and I stumbled upon uniform initializers.

我不明白以下應該顯示最令人煩惱的解析"歧義的代碼:

I don't understand the following code which should show the "most vexing parse" ambiguity:

#include<iostream>


class Timer
{
public:
  Timer() {}
};

int main() 
{

  auto dv = Timer(); // What is Timer() ? And what type is dv?

  int time_keeper(Timer()); // This is a function right? And why isn't the argument " Timer (*) ()" ?



  return 0;
}

推薦答案

這里:

auto dv = Timer();

您有一個名為 dvTimer 類型的對象,它正在從臨時對象(= 右側的表達式)復制初始化代碼> 符號).

You have an object of type Timer called dv that is being copy-initialized from a temporary (the expression on the right side of the = sign).

當使用 auto 聲明一個變量時,該變量的類型與初始化它的表達式的類型相同——這里不考慮 cv 限定符和引用.

When using auto to declare a variable, the type of that variable is the same as the type of the expression that initializes it - not considering cv-qualifiers and references here.

在您的情況下,初始化 dv 的表達式的類型為 Timer,因此 dv 的類型為 Timer.

In your case, the expression that initializes dv has type Timer, and so dv has type Timer.

這里:

int time_keeper(Timer());

您聲明了一個名為 time_keeper 的函數,它返回一個 int 并將指針作為它的輸入,該函數返回一個 定時器,不帶參數.

You declare a function called time_keeper that returns an int and takes as its input a pointer to a function which returns a Timer and takes no argument.

為什么不是參數 Timer (*) () ?

當作為參數傳遞時,函數衰減為指針,所以time_keeper的類型實際上是int(Timer(*)()).

Functions decay to pointers when passed as an argument, so the type of time_keeper is actually int(Timer(*)()).

為了說服自己,你可以嘗試編譯這個小程序:

To convince yourself, you could try compiling this little program:

#include <type_traits>

struct Timer { };
int main()
{
    int time_keeper(Timer());
    static_assert(
        std::is_same<
            decltype(time_keeper), 
            int(Timer(*)())
        >::value, 
        "This should not fire!");
}

這里有一個referar">noliver>>.

Here is a live example.

這篇關于最令人頭疼的解析混亂的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 另类二区 | 成人免费在线电影 | 婷婷色国产偷v国产偷v小说 | 中文字幕乱码一区二区三区 | 毛片一级片| 亚洲成人久久久 | 日韩欧美中文 | 韩国电影久久 | 亚洲精品天堂 | 久久精品视频99 | 亚洲 自拍 另类 欧美 丝袜 | 狠狠ri| 国产精品视频一区二区三区 | 综合久久久 | www.亚洲国产精品 | 中文字幕亚洲一区二区三区 | 国产精品九九九 | 秋霞国产 | h小视频| 日韩在线不卡视频 | 亚洲精品久久久久久一区二区 | 成人免费视频播放 | 一区二区成人在线 | 亚洲码欧美码一区二区三区 | 黄色一级电影在线观看 | 亚洲视频区 | www.99re| 国产精品99精品久久免费 | а天堂中文最新一区二区三区 | 欧美日韩一区二区三区四区 | 黄色免费在线网址 | 国产欧美一区二区在线观看 | 免费黄色成人 | 亚洲精品v| 国产一区二 | 国产精品久久久久久久久久99 | 欧美电影免费观看高清 | 在线免费观看日本 | 精品区 | 欧美日韩精品区 | 欧美视频成人 |