0

I am new to c++ and I want to include an array of Enum values, and I am getting a syntax error in Microsoft Visual Studio. I am not sure why this is the case any help much appreciated. The error number is C2061 and it states "syntax error: identifier 'VerboseBinary'. Here is the code:

Header file 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;

        }

Main

#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;
}
5
  • A downvote given with no reason why when I am a beginner is not very encouraging. Commented Sep 22, 2016 at 3:02
  • Please, read carefully stackoverflow.com/help/mcve You code is not minimal. You did not write line number of code with error. (I did not downvote you) Commented Sep 22, 2016 at 3:34
  • 1
    What version of Visual Studio are you using? enum with class became available with VS 2012. Also, there is a stray comma at the end of your enum's definition. Also, stdafx.h should appear before any other includes in verbose_binary.cpp. Main has a benign double-inclusion for <iostream>. Commented Sep 22, 2016 at 5:54
  • @ChristopherOicles thank you so much! Please post this as an answer if you want me to accept it. Commented Sep 22, 2016 at 6:20
  • After removing all the Microsoft-ese gobbledygook (namely the stdafx.h silliness), the shown code compiles without errors with gcc 6.1.1. Either the error is in the code that's not shown, or this is a compiler bug. Commented Sep 22, 2016 at 12:38

1 Answer 1

1

Lol, so it looks like one of these issues was resposible for the error:

  • What version of Visual Studio are you using? enum with class became available with VS 2012.

  • Also, there is a stray comma at the end of your enum's definition.

  • Also, stdafx.h should appear before any other includes in verbose_binary.cpp.

  • Main has a benign double-inclusion for <iostream>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.