Created
September 13, 2013 18:04
-
-
Save lucasmeijer/6554029 to your computer and use it in GitHub Desktop.
c++ template puzzle
This file contains 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
template<class T> struct Converter {}; | |
struct TheMagicTypeToFind {}; | |
struct MyConverter : Converter<TheMagicTypeToFind> //I want to store the magic type here | |
{ | |
void DoSomething(); | |
}; | |
template<class TMagic, class TConverter> | |
static void MyFunc(TConverter converter, Converter<TMagic>& onlyUsedForArgumentDeduction) | |
{ | |
TMagic magic; | |
converter.DoSomething(); | |
} | |
static void Main() | |
{ | |
MyConverter converter; | |
//how to change the code, so this double argument is not required, yet still all template arguments are autodeduced? | |
MyFunc(converter,converter); | |
} | |
//notes: | |
//- Need to be able to invoke DoSomething() | |
//- Dont want to make DoSomething virtual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment