views:

11

answers:

1

I guess I'm not understanding something about C++:

I have this code:

#include "window.h"

int main(int argc, char* argv[]) {
    Gtk::Main kit(argc, argv);
    window win();
    Gtk::Main::run(win);

    return EXIT_SUCCESS;
}

'window' is a class that inherits from Gtk::Window with an empty constructor. When I try to compile this code, I get this error:

no matching function for call to ‘Gtk::Main::run(window (&)())

However, if I change the line:

window win();

to

window win;

then the code compiles. How do the presence/absence of the parentheses change things? I've run into this before and never understood what was going on. What's happening?

+1  A: 

Because window win(); is the declaration of a function taking no parameters and returning a window. (Hence the error saying no matching call for window (&)(), which is that type.)

This is known as the "Most Vexing Parse."

GMan
Oh wow. That's kind of odd coming from a Java/C# background. Thanks for explaining that.
Jrop
@Jrop: Yeah, bit of a dark corner. No problem.
GMan