2016-04-26 82 views
-1

我不理解为什么这个预期的主要异常错误在那里! ...:'arrayName'之前预期的主表达式

Running /home/ubuntu/workspace/sample.cpp 
/home/ubuntu/workspace/sample.cpp: In function ‘int main()’: 
/home/ubuntu/workspace/sample.cpp:50:22: error: expected primary-expression before ‘arrayHelpfull’ 
      std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:51:10: error: expected primary-expression before ‘double’ 
      double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:52:22: error: expected primary-expression before ‘arrayNone’ 
      std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:53:10: error: expected primary-expression before ‘double’ 
      double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:54:23: error: expected primary-expression before ‘arrayHarmfull’ 
      std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:55:11: error: expected primary-expression before ‘double’ 
      double arrayHarmfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:61:20: error: expected primary-expression before ‘arrayHelpfull’ 
     std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:62:8: error: expected primary-expression before ‘double’ 
     double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:63:20: error: expected primary-expression before ‘arrayNone’ 
     std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:64:8: error: expected primary-expression before ‘double’ 
     double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:65:21: error: expected primary-expression before ‘arrayHarmfull’ 
     std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:66:9: error: expected primary-expression before ‘double’ 
     double arrayHarmfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:74:20: error: expected primary-expression before ‘arrayHelpfull’ 
     std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:75:8: error: expected primary-expression before ‘double’ 
     double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:76:20: error: expected primary-expression before ‘arrayNone’ 
     std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:77:8: error: expected primary-expression before ‘double’ 
     double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:78:21: error: expected primary-expression before ‘arrayHarmfull’ 
     std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:79:9: error: expected primary-expression before ‘double’ 
     double arrayHarmfullPoints[3], 
     ^

代码:

#include<iostream> 
#include<string> 
#include<fstream> 


void printingItems(


    std::string arrayHelpfull[3], 
    double arrayHelpfullPoints[3], 
    std::string arrayNone[3], 
    double arrayNonePoints[3], 
    std::string arrayHarmfull[3], 
    double arrayHarmfullPoints[3], 
    std::string option 

    ) { 
    std::cout << option << std::endl; 

} 


int main(){ 
    std::string arrayHelpfull[3] = {"fruits", "soda" , "candy"}; 
    double arrayHelpfullPoints[3] = {20.4,50.2,30.0}; 

    std::string arrayNone[3] = {"chair", "shoe" , "pencil"}; 
    double arrayNonePoints[3] = {0,0,0}; 

    std::string arrayHarmfull[3] = {"meth", "dirtyneedle","ninga"}; 
    double arrayHarmfullPoints[3] = {-20,-50,-30}; 

    int userChoice = 0; 
    while (userChoice != 4) { 

     std::cout << "1 - Just Plain Items" 
      << std::endl 
      << "2 - Helpfull Items" 
      << std::endl 
      << "3 - Harmfull Items" 
      << std::endl 
      << "4 - Quit" 
      << std::endl; 

     std::cin >> userChoice; 

     switch (userChoice) { 
     case 1: 
      printingItems(
      std::string arrayHelpfull[3], 
      double arrayHelpfullPoints[3], 
      std::string arrayNone[3], 
      double arrayNonePoints[3], 
      std::string arrayHarmfull[3], 
      double arrayHarmfullPoints[3], 
      "Plain" 
     ); 
      break; 
     case 2: 
     printingItems(
     std::string arrayHelpfull[3], 
     double arrayHelpfullPoints[3], 
     std::string arrayNone[3], 
     double arrayNonePoints[3], 
     std::string arrayHarmfull[3], 
     double arrayHarmfullPoints[3], 
     "Helpfull" 
     ); 

      break; 
     case 3: 

     printingItems(
     std::string arrayHelpfull[3], 
     double arrayHelpfullPoints[3], 
     std::string arrayNone[3], 
     double arrayNonePoints[3], 
     std::string arrayHarmfull[3], 
     double arrayHarmfullPoints[3], 
     "Harmfull" 
     ); 

      break; 
     } 


    } 
} 
+0

你需要一个[mcve]和一个问题。 – juanchopanza

+0

为什么在'printingItems'中的每个变量声明之后使用','而不是';'? – computerfreaker

+0

@computerfreaker它是一个功能参数列表。 – NathanOliver

回答

1
printingItems(
      std::string arrayHelpfull[3], 
      double arrayHelpfullPoints[3], 
      std::string arrayNone[3], 
      double arrayNonePoints[3], 
      std::string arrayHarmfull[3], 
      double arrayHarmfullPoints[3], 
      "Plain" 
     ); 

是不是你调用一个函数和变量传给它。您只需要将该变量的名称赋予该函数。你正在做的是试图在函数调用中重新声明变量。所有的函数调用应该看起来像

printingItems(arrayHelpfull, arrayHelpfullPoints, arrayNone, 
       arrayNonePoints, arrayHarmfull, arrayHarmfullPoints, "Plain"); 

您还需要使用一些一致的缩进。改变缩进使得代码非常难以阅读。

+0

Omg非常感谢!哇,让我好开心! 7分钟内无法接受 – amanuel2

相关问题