c++ - 在 ubuntu 12.10 中的 c++ 和 netbeans 中忽略了一条指令

标签 c++ g++ sdl

<分区>

Possible Duplicate:
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

对于我正在尝试制作的游戏项目,出于某种原因忽略了我创建对象的指令。

项目刚刚开始,我不知道为什么会这样。

我使用 netbeans 作为 ide,g++ 作为编译器,操作系统是 ubuntu 12.10。

发生这种情况的代码是这样的:

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

当我在“Motor m1();”上设置一个断点时并点击调试箭头跳转到它之后的返回指令并且不执行对象的构造函数

Motor 的代码是这样的:

#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)”用于测试目的。

为什么会这样?

最佳答案

Motor m1(); 

这意味着 m1 是一个不带参数并返回类 Motor 实例的函数。

你的意思是:

Motor m1;

这意味着默认构造类 Motor 的实例并将其命名为 m1

关于c++ - 在 ubuntu 12.10 中的 c++ 和 netbeans 中忽略了一条指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617410/

相关文章:

multithreading - C++0x 的 gcc 实验性实现的 std::future 异常

c++ - 使用c++11的std::thread,什么时候修改全局变量是线程安全的?

c++ - 编译器将 cpu 寄存器中的这种结构传递给函数是否有意义?

c++ - 仅在需要时编译文件

c++ - 在字节数组中嵌入多个整数

c++ - 在 C/C++ 中使用 SDL2_gfx 绘制实心圆

c++ - Opengl + SDL 链接错误

c++ - 写在文件上,信息最终出现在控制台中

c++ - 使用 -std=c++11 会破坏二进制兼容性吗?

c++ - TEXTUREACCESSes 的解释?