部分专门化模板内的方法指针

发布于 2024-10-09 01:29:41 字数 414 浏览 0 评论 0原文

我正在尝试实现具有只读、只写和读写行为的属性。我认为模板专业化将是这里的方法,所以我尝试了这个:

template<typename Class, typename Type, void (Class::*Set)(Type), Type (Class::*Get)(void)>
class Property;

template <typename Class, typename Type, Type (Class::*Get)(void)>
class Property<Class, Type, NULL, Get>
{
  ...
}

这不起作用并给出编译器错误(VC):部分专业化不能有依赖的非类型模板参数。

我在这里迷路了,这可能吗?

感谢您抽出时间, 理查德.

I'm trying to implement properties with readonly, writeonly and readwrite behaviour. I thought template specialization would be the way to go here, so I tried this:

template<typename Class, typename Type, void (Class::*Set)(Type), Type (Class::*Get)(void)>
class Property;

template <typename Class, typename Type, Type (Class::*Get)(void)>
class Property<Class, Type, NULL, Get>
{
  ...
}

This doesn't work and gives an compiler error (VC): a partial specialization cannot have a dependent non-type template parameter.

I'm lost here, is this at all possible?

Thanks for your time,
Richard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2024-10-16 01:29:41

您可以使用不太专业的方法,例如:

template<typename Class, typename Type, typename Get_functor, typename Set_functor>
class Property;

template <typename Class, typename Type, typename Get_functor>
class Property<Class, Type, NULL, Get_functor>
{
  ...
}

you can use less specialized approach like:

template<typename Class, typename Type, typename Get_functor, typename Set_functor>
class Property;

template <typename Class, typename Type, typename Get_functor>
class Property<Class, Type, NULL, Get_functor>
{
  ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文