C++ Problem (Advanced)

Started by
14 comments, last by Lethe 21 years, 9 months ago
I''m afraid your all iterating over stuff I allready know & have thought off, except for maby the half-life one - I''m not entirely sure whats going on there:-) I''m simply going to write it the way I originally thought of - and you have all sugested some part off! (With a few little bits I didn''t think off - thanks for those.)

I was just hoping for a solution with a shade more elegance.
Thanks to all.

-Lethe
Advertisement
XParam


Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
How does the solution lack elegance? You add a single call to a macro after you declare a class and you''re done. To create a new instance, you call a single function, passing the parameter you specified.

I don''t see what''s so ugly about it.
Umm, the fact that it is a macro implies that it lacks elegance.
Go back to flipcode.
quote:Original post by gumby
Umm, the fact that it is a macro implies that it lacks elegance.

Hardly, the macro lets you turn the parameter into a string literal in a deterministic manor - exactly what he needs to do. C++ is lacking in reflective features, so this isn''t an easy to do as it could be.

The other alternative is to use RTTI, which is ground to trend lightly on, as the resultant names are not deterministic (will be different on different compilers).
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
"Umm, the fact that it is a macro implies that it lacks elegance.
Go back to flipcode."

Will do sir. It''s obvious that your solution is much better. Oh wait, you didn''t post anything helpful here. I can only assume that the ''Go back to flipcode'' comment is some sort of intended insult.

And macros don''t imply that something isn''t elegant. There are plenty of legit uses for macros. There is no other way to create a factory for each class in a single simple function. He could get rid of the macro-ing all together and write out every factory by hand with some cut and pasting, but that kind of thing is exactly what macros are there for.

This topic is closed to new replies.

Advertisement