我已经粘贴了我正在处理的一段复杂模板代码的最低限度。
1 template <typename T>
2 class Base
3 : public T
4 {
5 public:
6 template <typename W, W& (T::ToImpl::*Func)()>
7 bool Foo();
8 };
9
10 template <typename T>
11 template <typename W, W& (T::ToImpl::*Func)()>
12 bool Base<T>::Foo()
13 {}
14
15 int
16 main()
17 {
18 return 0;
19 }
代码很简单,所以我不会解释任何东西。我无法使用 Visual Studio 2013(又名 VC++12)编译此代码。它给出了以下错误:
main.cc(13): error C2244: 'Base<T>::Foo' : unable to match function definition to an existing declaration
definition
'bool Base<T>::Foo(W)'
existing declarations
'bool Base<T>::Foo(W)'
出于好奇,我尝试用 g++ (4.4.7) 编译上面的代码,它编译得很好。
如果有人可以解释为什么代码无法在 Windows 上编译,我将不胜感激?修复会更甜蜜。:)