Created
September 7, 2011 21:24
-
-
Save herczy/1201782 to your computer and use it in GitHub Desktop.
Template specialization problem (outline)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is the original template | |
| template < typename _Type > | |
| class SomeClass | |
| { | |
| public: | |
| // Some functions | |
| void foo() | |
| { | |
| } | |
| void bar(int a) | |
| { | |
| } | |
| // etc. | |
| // This is what we want to specialize | |
| void specialize_me() | |
| { | |
| do_something(); | |
| } | |
| }; | |
| // BAD: We have to copy all functions even if they are the same | |
| template <> | |
| class SomeClass< SomeType > | |
| { | |
| public: | |
| // Some functions | |
| void foo() | |
| { | |
| } | |
| void bar(int a) | |
| { | |
| } | |
| // etc. | |
| // This is what we want to specialize | |
| void specialize_me() | |
| { | |
| do_something_else(); | |
| } | |
| }; | |
| // This would be ideal, but it doesn't compile with MSCV | |
| template <> | |
| SomeClass< SomeType >::specialize_me() | |
| { | |
| do_something_else(); | |
| } | |
| // So we solve it like this | |
| template < typename _Type > | |
| void outside_specialize_me() | |
| { | |
| do_something(); | |
| } | |
| template <> | |
| void outside_specialize_me() | |
| { | |
| do_something_else(); | |
| } | |
| template < typename _Type > | |
| class SomeClass | |
| { | |
| public: | |
| // Some functions | |
| void foo() | |
| { | |
| } | |
| void bar(int a) | |
| { | |
| } | |
| // etc. | |
| // This is what we want to specialize | |
| void specialize_me() | |
| { | |
| outside_specialize_me< _Type >(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment