Last active
December 23, 2015 00:29
-
-
Save lucasmeijer/6554039 to your computer and use it in GitHub Desktop.
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
//PUZZLE: This code compiles, but requires an ugly double argumetn on line 27. How to change the code so | |
//this is not required, yet the TMagic type is still automatically deduced? | |
// | |
//- Dont want to make DoSomething virtual | |
//- compile with gcc -c test.cpp | |
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; | |
MyFunc(converter,converter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment