类外的成员模板函数定义无法生成Visual studio 2013
Member template function definition outside class fails to build Visual studio 2013
我已经粘贴到了我正在处理的一段复杂模板代码的最底层。
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上编译,我将不胜感激?修复会更甜蜜。:)
这应该有效:
template <typename T>
struct to_impl
{
typedef typename T::ToImpl type;
};
template <typename T>
class Base
: public T
{
public:
template <typename W, W& (to_impl<T>::type::*Func)()>
bool Foo();
};
template <typename T>
template <typename W, W& (to_impl<T>::type::*Func)()>
bool Base<T>::Foo()
{
}
尽管在Base
:中实现Foo
会更容易
template <typename T>
class Base
: public T
{
public:
template <typename W, W& (T::ToImpl::*Func)()>
bool Foo()
{
}
};
相关文章:
- 将"libpqxx"与Visual Studio 2013链接/安装,以便与PostgrSQL建立C++连接
- Visual Studio 2013,错误 MSB8020:找不到 Visual Studio 2010 的生成工具
- 为什么在Visual Studio 2013上的std::this_thread::sleep_for上死锁
- Visual Studio Professional 2013, Update 5, "No Target Architecture"
- 性能报告 (.vspx) 在 Visual Studio 2013 中未打开(显示损坏)
- 在 Visual Studio 2013 中使用零大小数组C++
- Visual Studio 2013 标头包含失败
- 是与视觉C 2017二进制文件兼容的Visual C 2013二进制文件
- C /FORTRAN项目由Visual Studio 2010/Intel 2013创建,将不会在Visual St
- Visual studio 2013 和 g++ 7.1 中将 int 和 long 类型相乘时的 c++ 差异行为
- 如何修复此错误,该错误在2013年Visual Studio上构建VirtualPlannetBuilder源
- 在Visual Studio 2013中编译的STL列表代码在Visual Studio 2019中给出了错误.想知道原
- 错误 LNK2019: 未解析的外部符号 Visual Studio 2013 与 openCV
- cv:内存位置的异常 - 运行 openCV 代码 Visual Studio 2013 & Visual Studio 2017 - Windows 7
- 模块计算机类型和目标计算机类型 Visual Studio 2013
- 如何在Visual Studio 2013 Ultimate Edition中包含某个单词的每一行中插入断点
- 具有显式参数和大小的可变参数模板.Visual Studio 2013.
- 使用 Visual Studio 2013 编译 GDCM dlls 2.8.4 for Windows
- 如何将lapack与CMake和Visual 2013联系起来
- Visual 2013 插件,用于记录您在项目上工作的时间。