![]() |
|
Template specialization of a method - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Template specialization of a method (/thread-5320.html) |
Template specialization of a method - Fenris - Jul 10, 2005 06:49 AM I have a templatized base class, and I want to specialize one of its methods (to control its return type). That means I define the class, let's say, as template <typename T> A. Now, all of its member functions need to be: Code: template <typename T> A<T>::MyFuncTemplate specialization of a method - OneSadCookie - Jul 10, 2005 02:32 PM eg. Code: template <class T>Template specialization of a method - Fenris - Jul 11, 2005 12:22 AM Aaah, thanks. Template specialization of a method - Fenris - Jul 11, 2005 05:17 AM Right, I'm going to have to ask for some more help and insight here... What I'm trying to achieve is a base class for a singleton, so that all my singleton classes can be derived off of it. So, I set about to create it, and it worked fairly well, apart from one little caveat: Code: static class bmSingleton* Instance (void) {return _instance;}Code: myManager::Instance()->subclassedManagerDataSo, what I wanted to do was then to templatize this bmSingleton class so that I can pass in the type of the subclass and get the correct return type of the Instance() method, and a static instance pointer for each singleton type. My header: Code: template <class T>Question #1: Is this even feasible? Will I actually get a separate instance pointer for each template class? Or will they still share some kind of confused instance pointer? Question #2: The final line gives me a 'syntax error before ::' - any guesses as to why? Question #3: Is it at all possible to send the bmSingleton, as a template type parameter, a subclass of itself? Can it contain a pointer to a subclass of itself? All insight is very appreciated. Template specialization of a method - OneSadCookie - Jul 11, 2005 02:45 PM singleton.hpp Code: #ifndef singleton_hppCode: #ifndef x_hppCode: #include "x.hpp"Code: #include "x.hpp" |