Enum作为c++参数的数组
Enum Array as parameter c++
我是c++的新手,我想包含枚举值的数组,我在Microsoft Visual Studio中得到语法错误。我不知道为什么会这样,非常感谢任何帮助。错误编号是C2061,它指出"语法错误:标识符'VerboseBinary'"。下面是代码:
头文件verbose_binary.h
#pragma once
#include <bitset>
enum class VerboseBinary : int {
One,
Two,
Four,
Eight,
Sixteen,
Null,
};
void convert(std::bitset<5> bs, VerboseBinary aVB[6]);
verbose_binary.cpp
#include "verbose_binary.h"
#include "stdafx.h"
#include <bitset>
#include <string>
#include <iostream>
void convert(std::bitset<5> bs, VerboseBinary aVB[6]) {
VerboseBinary VBArray[6] = {
VerboseBinary:: One,
VerboseBinary:: Two,
VerboseBinary:: Four,
VerboseBinary:: Eight,
VerboseBinary:: Sixteen,
VerboseBinary:: Null
};
for (int i = 0; i < 5; i++) {
if (bs.test(i)) {
aVB[i] = VBArray[i];
}
else {
aVB[i] = VerboseBinary::Null;
}
}
aVB[5] = VerboseBinary::Null;
}
主要#include "stdafx.h"
#include <iostream>
#include <iostream>
#include <bitset>
#include "verbose_binary.h"
int main() {
int a, b;
std::bitset<5> aBs, bBs;
std::cout << "Enter two numbers between 0-31:" << std::endl;
std::cin >> a >> b;
if (a<0 || a>31) return -1;
if (b<0 || b>31) return -2;
aBs = static_cast<std::bitset<5>>(a);
bBs = static_cast<std::bitset<5>>(b);
// std::cout << aBs << " " << bBs << std::endl;
VerboseBinary aVB[6];
VerboseBinary bVB[6];
convert(aBs, aVB);
convert(bBs, bVB);
return 0;
}
Lol,所以看起来这些问题之一是导致错误的原因:
-
您使用的是哪个版本的Visual Studio ?带类的enum在VS 2012中可用。
-
另外,在枚举定义的末尾有一个逗号。
-
此外,stdafx.h应该出现在verbose_binary.cpp中的任何其他包含之前。
-
Main对
<iostream>
具有良性双包合
相关文章:
- C++函数模板需要 &for 数组参数
- C++ 数组参数不起作用
- 使用数组参数进行函数专用化
- 为什么我的数组参数的方法无法正常工作?(C )
- SWIG - Java 代理类数组参数
- 在 gcc 中使用数组参数编译外部"c"代码
- 从 VB6 调用的 C++ DLL 函数中的输出数组参数
- 如何根据数组参数项类型重载 IDL 中的函数
- 引用谷歌测试/模拟框架中的数组参数
- C++将数组参数传递给函数
- 字符星形数组参数未正确终止
- 如何将德尔菲的"字符串数组"参数翻译成C++?
- 为什么 gcc 无法推断数组参数的模板化大小?(C++11)
- 使用 const char 数组参数分析 constexpr 显示运行时执行
- C++指针数组参数
- 固定大小的多维数组参数
- 为什么数组参数被视为常量数组
- 如何在pgsql中格式化数组参数
- C++字符数组参数在x86编译中包含奇怪的字符
- 对象数组参数 - 错误:字段“字母”的类型不完整