如何克服GCC限制“不能将模板参数'0'转换为'Foo *'”? [英] How to overcome GCC restriction "could not convert template argument '0' to 'Foo*'"?

查看:128
本文介绍了如何克服GCC限制“不能将模板参数'0'转换为'Foo *'”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这样的代码:

template<class T, T initial_t> class Bar {
  // something
}

然后尝试使用它像这样:

And then try to use it like this:

Bar<Foo*, NULL> foo_and_bar_whatever_it_means_;

GCC退出时出错(在上面一行):

GCC bails out with error (on the above line):


无法将模板参数
'0'转换为'Foo *'

could not convert template argument '0' to 'Foo*'

我找到此主题: http://gcc.gnu .org / ml / gcc-help / 2007-11 / msg00066.html ,但我必须在这种情况下使用NULL(确定,我可能重构 - 但它不会是微不足道的;任何建议?)。我试图克服这个问题,通过创建一个值为NULL的变量,但GCC仍然抱怨我传递变量,而不是变量的地址作为模板参数。

I found this thread: http://gcc.gnu.org/ml/gcc-help/2007-11/msg00066.html, but I have to use NULL in this case (ok, I could probably refactor - but it would not be trivial; any suggestions?). I tried to overcome the problem by creating a variable with value of NULL, but GCC still complains that I pass variable and not address of variable as a template argument. And reference to a variable initialized with default ctor would not be the same as NULL.

推荐答案

重新思考你的代码可能是最好的方法绕过它。您链接到的线程包括标准的明确报价,表示不允许。

Rethinking your code is probably the best way to get around it. The thread you linked to includes a clear quote from the standard indicating that this isn't allowed.

这篇关于如何克服GCC限制“不能将模板参数'0'转换为'Foo *'”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆