Hi again, The output of, for example #include <ginac/ginac.h> using namespace GiNaC; main() { symbol x("x"), y("y"); std::cout << ex_to_add(x+y).get_precedence() << std::endl; } should be 40 but I am getting 70 It seems to me that one has to define for each class, that redefines basic::precedence, also the get_precedence() function. Clearly it is not C++ way, but may be it is due to that basic::precedence is defined static. Sorry, but right now I don't have any idea how to fix it... Pearu
On Wed, 16 May 2001, Pearu Peterson wrote:
It seems to me that one has to define for each class, that redefines basic::precedence, also the get_precedence() function. Clearly it is not C++ way, but may be it is due to that basic::precedence is defined static. Sorry, but right now I don't have any idea how to fix it...
Thanks Pearu for the bugreport. Your analysis is correct. Christian, we've had the same trouble when we tried to make default_overall_coeff() an inline function in class expairseq returning a protected static ex(1) or ex(0) respectively for classes mul and add. This just doesn't work with static member variables. All alternatives which come to my mind are either preprocessor-based or replicate data and either way as ugly as sin. Any really good suggestion? Regards -richy. -- Richard Kreckel <Richard.Kreckel@Uni-Mainz.DE> <http://wwwthep.physik.uni-mainz.de/~kreckel/>
On Wed, 16 May 2001, Richard B. Kreckel wrote:
On Wed, 16 May 2001, Pearu Peterson wrote:
It seems to me that one has to define for each class, that redefines basic::precedence, also the get_precedence() function. Clearly it is not C++ way, but may be it is due to that basic::precedence is defined static. Sorry, but right now I don't have any idea how to fix it...
Thanks Pearu for the bugreport. Your analysis is correct.
Christian, we've had the same trouble when we tried to make default_overall_coeff() an inline function in class expairseq returning a protected static ex(1) or ex(0) respectively for classes mul and add. This just doesn't work with static member variables. All alternatives which come to my mind are either preprocessor-based or replicate data and either way as ugly as sin. Any really good suggestion?
I played a bit with possible solutions (assuming static precedence) and it seems that simplest solution is inserting the following line public: unsigned get_precedence(void) const {return precedence;} to the macro GINAC_DECLARE_REGISTERED_CLASS (Note that then there is little reason to keep basic::get_precedence()) Optimal (for the compiler but not for the programmer, I guess) solution is: When redefining precedence, redefine also get_precedence() in derived class. What do you think? Pearu
Hi! On Thu, May 17, 2001 at 11:22:21PM +0200, Pearu Peterson wrote:
seems that simplest solution is inserting the following line public: unsigned get_precedence(void) const {return precedence;} to the macro GNAC_DECLARE_REGISTERED_CLASS
This seems to work. Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
On Fri, 18 May 2001, Christian Bauer wrote:
Hi!
On Thu, May 17, 2001 at 11:22:21PM +0200, Pearu Peterson wrote:
seems that simplest solution is inserting the following line public: unsigned get_precedence(void) const {return precedence;} to the macro GNAC_DECLARE_REGISTERED_CLASS
This seems to work.
Sorry to bother again but it does not. Namely, some classes, such as symbol, does not use GNAC_DECLARE_REGISTERED_CLASS, and as a consequence one cannot use symbol::get_precedence() (which is silly, of cource). As a fix (to the latest CVS version), there are two possibilities: 1) put basic::get_precedence() back again --- this will work if it is **absolutely sure** that classes with no storage will not define their own precedence (not now and not in future). 2) insert public: unsigned get_precedence(void) const {return precedence;} to macro GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS so that all GiNaC classes will have their own get_precedence() method. I think this is safest solution. Regards, Pearu
Hi! On Sat, May 19, 2001 at 02:05:40AM +0200, Pearu Peterson wrote:
Sorry to bother again but it does not. Namely, some classes, such as symbol, does not use GNAC_DECLARE_REGISTERED_CLASS, and as a consequence one cannot use symbol::get_precedence() (which is silly, of cource).
I've now replaced the static member variable by a virtual function precedence(), hopefully bringing this to an end. Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
On Sat, 19 May 2001, Christian Bauer wrote:
Hi!
On Sat, May 19, 2001 at 02:05:40AM +0200, Pearu Peterson wrote:
Sorry to bother again but it does not. Namely, some classes, such as symbol, does not use GNAC_DECLARE_REGISTERED_CLASS, and as a consequence one cannot use symbol::get_precedence() (which is silly, of cource).
I've now replaced the static member variable by a virtual function precedence(), hopefully bringing this to an end.
Thanks! It now works perfectly. Regards, Pearu
participants (3)
-
Christian Bauer
-
Pearu Peterson
-
Richard B. Kreckel