
Originally Posted by
jamadagni
1. Why don't you declare it as MyPushButton *b = new MyPushButton(); ?
QPushbutton *b = new MyPushButton(); creates a new QPushbutton called b and assigns it a pointer to memory containing an instance of MyPushButton(). But now it is also possible later to change b to point to an instance of MyOtherPushButton or any other subclass of QPushButton.
If you were to try
MyPushButton *b = new MyPushButton();
MyPushButton *b = new MyPushButton();
To copy to clipboard, switch view to plain text mode
and then later
b = new MyOtherPushButton();
b = new MyOtherPushButton();
To copy to clipboard, switch view to plain text mode
you would get an "invalid conversion from type x to type y" error. The way you are wanting to write it is fine for most things. But to say the IDE must autocomplete this type of statement would be for it to make unnecessary guesses and handholding for the programmer.
Bookmarks