1

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

An instruction where i create an object is being ignored for some reason for a project of a game im trying to make.

The project is is just being started, i have no idea why is happening.

Im using netbeans as ide, g++ as the compiler and the OS is ubuntu 12.10.

the code where this is happening is this:

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

when i put a break point on "Motor m1();" and hit debug the arrow jumps to the return instruction after it and the constructor of the object is not executed

the code for Motor is this:

#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();
}

the "SDL_Delay(2000)" is there for testing purposes.

Why is this happening?

Community
  • 1
  • 1
Zeroth
  • 13
  • 2

1 Answers1

3
Motor m1(); 

This means that m1 is a function that takes no parameters and returns an instance of class Motor.

You mean:

Motor m1;

This means to default construct an instance of class Motor and call it m1.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278