[英]what does “ error: conversion from 'double' to 'std::size_t' (aka 'unsigned long') is not allowed in a converted constant expression” mean?
#define Tag std::bitset<32-8-log2(4*_N)>
#define Offset std::bitset<log2(4*_N)>
I tried to write a code in cpp with the following #define functions and i ended up with the error.我尝试使用以下 #define 函数在 cpp 中编写代码,但最终出现错误。
error: conversion from 'double' to 'std::size_t' (aka 'unsigned long') is not allowed in a converted constant expression
Tag* _tagBits;
You could define your own constexpr
(naive) log2:您可以定义自己的
constexpr
(naive) log2:
#include <iostream>
#include <bitset>
constexpr std::size_t log2(std::size_t N)
{
return N <= 1 ? 0 : 1+log2(N/2);
}
int main()
{
std::bitset<1+log2(13)> b;
std::cout << b << '\n'; // 0000
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.