2012-11-29 62 views
1

可能重複:
Why is there no call to the constructor?
What’s the effect of 「int a(); 」 in C++?
What’s the differences between Test t; and Test t();? if Test is a class的指令時在C++和NetBeans被忽略在Ubuntu 12.10

其中i創建一個對象被忽略的指令一個遊戲項目的一些原因,我試圖做出。

該項目剛剛開始,我不知道爲什麼會發生。

我使用netbeans作爲ide,g ++作爲編譯器,操作系統是Ubuntu 12.10。

其中發生這種情況的代碼是這樣的:

#include "Vector.h" 
#include"Motor.h" 
int main(int argc, char** argv) 
{ 
    Motor m1(); 
    return 0; 
} 

當我把一個斷點上的「電機M1();」並創下調試箭頭跳轉到返回指令後,不執行

用於電機代碼的對象的構造是這樣的:

#include "Motor.h" 
Motor::Motor() { 
    SDL_Init(SDL_INIT_EVERYTHING); 
    pantalla=NULL; 
    pantalla=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE); 

    SDL_Delay(2000); 
} 
Motor::~Motor() { 
    SDL_Quit(); 
} 

的「SDL_Delay(2000)」是有測試目的。

這是怎麼發生的?

+0

'電機m1();'不會做你認爲它的工作。 –

回答

3
Motor m1(); 

這意味着m1是不帶參數,並返回Motor類的實例的功能。

你的意思是:

Motor m1; 

這意味着默認構造Motor類的實例,並調用它m1

+0

好的,謝謝。現在它工作了。 – Zeroth