Template
1

2018

1

以下皆为在开发我的 C++ 库 donnylib 的时候遇到的问题。 (一天遇到这么多 weird problems 也是很走运了) donnylib : https://github.com/Donny-Hikari/donnylib Weird Template Subclass 如下的程序会导致无法自动推断模板类型。(编译环境: g++ 5.4.0, -std=c++17) template<class T> struct FOO { struct NOT { NOT() { } }; FOO() { sizeof(T); } }; template<class T> typename FOO<T>::NOT foo(typename FOO<T>::NOT a) { return a; } void test1() { FOO<int>::NOT f; foo(f); // template argument deduction/substitution failed. } 加上下面的代码也是不行的。 template<class T> using NOT = typename FOO<T>::NOT; template<class T> NOT<T> foo(NOT<T