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

使用 () 或不使用 () 創建對象的區別

Difference between creating object with () or without(使用 () 或不使用 () 創建對象的區別)
本文介紹了使用 () 或不使用 () 創建對象的區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我剛遇到這個問題

error: request for member ‘show’ in ‘myWindow’, which is of non-class type ‘MainGUIWindow()’

嘗試編譯一個簡單的 qt 應用程序時:

when trying to compile a simple qt-application:

#include <QApplication>
#include "gui/MainGUIWindow.h"


int main( int argc, char** argv )
{
  QApplication app( argc, argv );


  MainGUIWindow myWindow();
  myWindow.show();


  return app.exec();
}

我通過替換

MainGUIWindow myWindow(); 

MainGUIWindow myWindow;

但我不明白其中的區別.我的問題:有什么區別?

but I don't understand the difference. My question: What is the difference?

問候,德克

推薦答案

其他答案正確地指出括號版本實際上是一個函數聲明.為了直觀地理解它,假設你寫的 MainGUIWindow f(); 看起來更像一個函數,不是嗎?:)更有趣的問題是

The other answers correctly state that the parentheses version is actually a function declaration. To understand it intuitively, suppose you wrote MainGUIWindow f(); Looks more like a function, doesn't it? :) The more interesting question is what is the difference between

MainGUIWindow* p = new MainGUIWindow;

MainGUIWindow* p = new MainGUIWindow();

帶括號的版本稱為值初始化,而沒有括號的版本稱為默認初始化.對于非 POD 類,兩者沒有區別.然而,對于 POD 結構,值初始化涉及將所有成員設置為 0,

The version with parentheses is called value-initialization, whereas the version without is called default-initialization. For non-POD classes there is no difference between the two. For POD-structs, however, value-initialization involves setting all members to 0,

my2c

補充:一般來說,如果某個句法結構既可以解釋為聲明又可以解釋為其他東西,編譯器總是會以聲明的方式解決歧義.

Addition: In general, if some syntactic construct can be interpreted both as a declaration and something else, the compiler always resolves the ambiguity in favor of the declaration.

這篇關于使用 () 或不使用 () 創建對象的區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 ()?環形?)
主站蜘蛛池模板: 久久精品网 | 国产精品成人av | 中文字幕亚洲欧美 | 国产精品欧美精品 | 国产91九色 | 一本一道久久a久久精品蜜桃 | 成人精品一区 | 日本成人中文字幕 | 久久精品国产久精国产 | 免费成人高清在线视频 | 精品一区二区在线视频 | 色男人的天堂 | 国产日韩一区二区三区 | 黄色a视频| 久久久美女 | 久草视频在线播放 | 一级片aaa | 国产精品免费一区二区三区 | 久久久久久久一区 | 视频在线一区二区 | 久久99精品久久久久久国产越南 | 久久亚洲精品国产精品紫薇 | 欧美一区二区三区在线播放 | 男人天堂久久久 | 大乳boobs巨大吃奶挤奶 | 久久久久国产一区二区三区四区 | 亚洲成人观看 | 国产精品久久久久999 | 久久久精| 97精品超碰一区二区三区 | 午夜成人免费视频 | 懂色av色香蕉一区二区蜜桃 | 亚洲精品久久久 | 毛片在线免费播放 | 欧美综合在线视频 | 成人精品一区 | 国产在线aa | 成人午夜在线 | 看特级黄色片 | 在线观看中文字幕 | 日韩免费一区二区 |