If for no other reason than for my own amusement, I wish to write a global insertion operator so I can use the fancy code:
aQMenu << aQAction1 << aQAction2 << aQAction2 << seperator << aQAction3;
Perhaps you hate the syntax, but I would at least like to try my hand at using it. The problem is, that this is the first time I have tried to write insertion operator code, and I am stumped. The code for inserting the enum "seperator" to the QMenu* is easy, and I have that working, but I thought this code would work for inserting a QAction* to a QMenu*:
// does not compile: "must have an argument of class or enumerated type"
QMenu *operator<< (QMenu *menu, QAction *action)
{
menu->addAction(action);
return menu;
}
The compiler complains saying this function needs an argument of a class or enumerated type, which confounds me because the second parameter is of class type.. I have tried to rephrase this function using the ampersand, but I have not hit upon the way of writing it down properly. I have looked a lot at web examples, and thought it is about time to just as the question here.
I know that some coders out there will complain about me deviating from standard Qt syntax, but I am having fun overloading the operator<< with other classes as well. It just seems that the insertion operator works nicely here. What can I say -- it makes me happy.