0
我是新来的c + +,我想包括一个枚举值的数组,我在Microsoft Visual Studio中出现语法错误。我不知道为什么这是非常赞赏的任何帮助。错误编号是C2061和它指出“语法错误:识别符 'VerboseBinary' 这里是代码:枚举数组作为参数c + +
头文件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;
}
,没有理由为什么当我是一个初学者并不十分令人鼓舞给的downvote。 – IntegrateThis
请仔细阅读http://stackoverflow.com/help/mcve您的代码不是最小的。你没有写错误的代码行号。 (我没有downvote你) – SergV
你使用的是什么版本的Visual Studio?带有'class'的'enum'在VS 2012中可用。而且,在枚举定义结尾处有一个逗号逗号。而且,stdafx.h应该出现在verbose_binary.cpp中的任何其他包含之前。 Main对''有良性双重包含。 –