2016-09-22 82 views
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; 
} 
+0

,沒有理由爲什麼當我是一個初學者並不十分令人鼓舞給的downvote。 – IntegrateThis

+0

請仔細閱讀http://stackoverflow.com/help/mcve您的代碼不是最小的。你沒有寫錯誤的代碼行號。 (我沒有downvote你) – SergV

+1

你使用的是什麼版本的Visual Studio?帶有'class'的'enum'在VS 2012中可用。而且,在枚舉定義結尾處有一個逗號逗號。而且,stdafx.h應該出現在verbose_binary.cpp中的任何其他包含之前。 Main對''有良性雙重包含。 –

回答

1

大聲笑,所以它看起來像這些問題之一是resposible的錯誤:

  • 您使用的是什麼版本的Visual Studio? enum with class在VS 2012中可用。

  • 另外,在枚舉的定義結尾處有一個逗號逗號。

  • 此外,stdafx.h應該出現在verbose_binary.cpp中的任何其他包含之前。

  • 主要有良性的雙重包容<iostream>