I have a template method that is designed to work with a specific set of classes. Since I have no real need for runtime polymorphism, I’ve decided to not use pointers to the parent class, but rather will have the compiler put everything together for me.
I want to either restrict the type that can be passed to the template, or make GCC issue sensible errors when an incorrect type is passed.
Is this possible?
Yes. It is possible using a number of different techniques depending on the specific needs of the day. There’s boost::enable_if. There’s MPL and static_assert…(use BOOST_STATIC_ASSERT if you’re not using a C++0x compiler). There’s Boost.Concepts.
Yes. It is possible.