2014-12-05 584 views
-3

所以我试图开始调试我的代码有什么问题,但我目前有一个问题,我不明白的错误。使用代码块通过Oracle虚拟机。我很确定问题在于我的代码的标题,但我会发布整个事情。C++错误“预期的非限定id”('令牌“在调试之前

我想构建一个使用头文件,原型, 。和功能到目前为止,我只需要基本的数学工作

错误Messege写着: || ===体形:调试在贾维斯。(编译:GNU GCC编译)=== | /家庭/用户/ Dropbox的/ Lecture36CompilationAnd内存/ JARVIS/JARVIS.h | 1 |错误:预期在''''令牌|之前的非限定ID || ===构建失败:1个错误,0个警告(0分(s),0秒(s))=== |

的main.cpp

#include <iostream> 
#include <string> 
#include "JARVIS.h" 

using namespace std; 

int main() 
{ 
    string command; 
    bool jarvis_running = false; 
    cout << "J.A.R.V.I.S" << endl; 
    cout << "Give a command from the list of commands available." << endl; 
    cin >> command; 

    if (command == "-h") 
    { 
     jarvis_running = true; 
     cout << "The available commands are: math" << endl; 
    } 

    if (command = "math") 
    { 
     jarvis_running = true; 
     math(); 
    } 

    if (jarvis_running == false) 
    { 
     cout << "That command was not valid" << endl; 
     cout << "Type '-h' if you need to know the available commands." << endl; 
    } 

    return 0; 
} 

* JarvisFunctions.cpp

#include <iostream> 
#include <string> 
#include "JARVIS.h" 

using namespace std; 

int math() 
{ 
    char mathCommand; 

    cout << "(A)ddition, (S)ubtraction, (M)ultiplication, or (D)ivision?" << endl; 
    cin >> mathCommand; 

    if (mathCommand == "A") 
    { 
     cout << "input the two integers you are adding" << endl; 
     cin >> integer1 >> integer2; 

     math.setValues(integer1, integer2); 
     addition add; 
    } 


    else if(mathCommand == "S") 
    { 
     cout << "input the two integers you are subtracting" << endl; 
     cin >> integer1 >> integer2; 

     math.setValues(integer1, integer2); 
     subtraction sub; 
    } 

    else if(mathCommand == "M") 
    { 
     cout << "input the two integers you are multiplying" << endl; 
     cin >> integer1 >> integer2; 

     math.setValue(integer1, integer2); 
     mulitplication multi; 
    } 

    else if(mathCommand == "D") 
    { 
     cout << "input the two integers you are dividing" << endl; 
     cin >> integer1 >> integer2; 

     math.setValues(integer1, integer2); 
     division div; 
    } 

    else 
    { 
     cout << "you did not input the right fuctions, either use A, S, M, or D" << endl; 
    } 
} 

JARVIS.h

#ifndef JARVIS_H 
    #define JARVIS_H 

    int math(); 

    class math 
    { 
     private: 
     int val1; 
     int val2; 

     public: 

     math() 
     { 
      cout<<"calling math constructor"<<endl; 
     } 

     void setValues (int a, int b){ 
      val1 = a; 
      val2 = b; 
     } 

     ~math() 
     { 
      cout<<"calling math deconstructor"<<endl; 
     } 

    }; 

    int addition:public math 
    { 
     finalVal = val1 + val2; 
     return finalVal; 
    }; 

    int subtraction:public math 
    { 
     finalVal = val1 - val2; 
     return finalVal; 
    }; 

    int multiplication:public math 
    { 
     int finalVal = val1 * val2; 
     return finalVal; 
    }; 

    int division:public math 
    { 
     int finalVal = val1/val2; 
     return finalVal; 
    }; 

    #endif //JARVIS_H 
+2

,如果你给我们确切的情况和错误这个问题就会感觉到好了很多消息也是如此。 – xtofl 2014-12-05 12:42:12

回答

0

有你有什么很多的误解。你真的应该花更多的时间与你学习的任何资源。

的main.cpp

#include <iostream> 
#include <string> 
#include "JARVIS.h" 

int main() 
{ 
    std::string command; 
    bool jarvis_running = false; 
    std::cout << "J.A.R.V.I.S" << std::endl; 
    std::cout << "Give a command from the list of commands available." << std::endl; 
    std::cin >> command; 

    if (command == "-h") 
    { 
     jarvis_running = true; 
     std::cout << "The available commands are: math" << std::endl; 
    } 

    if (command == "math") 
    { 
     jarvis_running = true; 
     int result = math(); 
     std::cout << "result = " << result << std::endl; 
    } 

    if (jarvis_running == false) 
    { 
     std::cout << "That command was not valid" << std::endl; 
     std::cout << "Type '-h' if you need to know the available commands." << std::endl; 
    } 

    return 0; 
} 

JARVIS.h

#ifndef JARVIS_H 
#define JARVIS_H 

#include <iostream> 

int math(); 

class Math 
{ 
    private: 
    int val1; 
    int val2; 

    public: 

    Math() 
    { 
     std::cout<<"calling math constructor"<<std::endl; 
    } 

    void setValues (int a, int b){ 
     val1 = a; 
     val2 = b; 
    } 

    ~Math() 
    { 
     std::cout<<"calling math deconstructor"<<std::endl; 
    } 


    int addition() 
    { 
     int finalVal = val1 + val2; 
     return finalVal; 
    } 

    int subtraction() 
    { 
     int finalVal = val1 - val2; 
     return finalVal; 
    } 

    int multiplication() 
    { 
     int finalVal = val1 * val2; 
     return finalVal; 
    } 

    int division() 
    { 
     int finalVal = val1/val2; 
     return finalVal; 
    } 

}; 

#endif //JARVIS_H 

JarvisFunctions.cpp

#include <iostream> 
#include <string> 
#include "JARVIS.h" 

int math() 
{ 
    std::string mathCommand; 

    std::cout << "(A)ddition, (S)ubtraction, (M)ultiplication, or (D)ivision?" << std::endl; 
    std::cin >> mathCommand; 

    int integer1, integer2; 

    // create an instance of Math class 
    Math m; 
    if (mathCommand == "A") 
    { 
     std::cout << "input the two integers you are adding" << std::endl; 
     std::cin >> integer1 >> integer2; 

     m.setValues(integer1, integer2); 
     return m.addition();; 
    } 


    else if(mathCommand == "S") 
    { 
     std::cout << "input the two integers you are subtracting" << std::endl; 
     std::cin >> integer1 >> integer2; 

     m.setValues(integer1, integer2); 
     return m.subtraction(); 
    } 

    else if(mathCommand == "M") 
    { 
     std::cout << "input the two integers you are multiplying" << std::endl; 
     std::cin >> integer1 >> integer2; 

     m.setValues(integer1, integer2); 
     return m.multiplication(); 
    } 

    else if(mathCommand == "D") 
    { 
     std::cout << "input the two integers you are dividing" << std::endl; 
     std::cin >> integer1 >> integer2; 

     m.setValues(integer1, integer2); 
     return m.division(); 
    } 

    else 
    { 
     // TODO: add some sort of error handling 
     std::cout << "you did not input the right fuctions, either use A, S, M, or D" << std::endl; 
     return 0; 
    } 

} 
相关问题