使用模板定义bitset的大小 [英] Defining the size of bitset using a template

查看:195
本文介绍了使用模板定义bitset的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类

template <class MAX> 
class A 
{
   std::bitset<MAX> _mem ; 
}

这个类的目的是使我可以有可变长度的比特组。在我的程序的不同部分使用。

The aim of this class , is so that I can have variable length bitsets. To be used in different parts of my program.

但是clang complete给我的错误

But clang complete gives me the error

template argument for non type template parameter should be an expression


推荐答案

$ c> bitset template期望一个常量的整数表达式,而不是一个类型。尝试此操作:

The bitset template expects a constant integral expression, not a type. Try this:

template < size_t MAX >
class A { std::bitset<MAX> _mem; };

这篇关于使用模板定义bitset的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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