Thread: errors.. errrors.. more errors

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    errors.. errrors.. more errors

    line 10 is this line

    Code:
    class item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, item28, item29, item30;
    the error is

    parse error before `,'
    line 376 is this one
    Code:
       gold=75, health=100, magic=60, attack=3, aim=7, defence=9, item1=wizardybook, item2=basicstaff, item3=robe, item4=manapotion, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
    with the error
    parse error before `='

    line 398 is
    Code:
     fout >> "Inventory Item 1: " << item1 << endl;
    with error

    no match for `ofstream & >> const char[19]'
    i havnt gotta clue why this errors ocure, if u neeed to see more lines say so
    Last edited by Klinerr1; 07-22-2002 at 12:14 PM.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    First error:

    You're declaring multiple classes like multiple variables. You can't do that; I have a feeling you didn't mean to use "class".

    Second error:

    You either missed a variable type, or you're trying to set the values of multiple predefined variables all in one line using commas. If it's the first, add the variable type. If it's the second, you need to separate them using semicolons, not commas.

    Third error:

    Assuming "fout" is just a typo specific to here, the first thing is an input operator; it should be an output operator.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    1. class is a keyword, it looks here like you've used it to identify a class. Try using something similar, eg
    Code:
    class MyClass
    {
    //definition
    };
    
    MyClass item1, item2;  //etc, etc.
    2. not so sure about the 2nd error, it may be related to the first though.

    3. Assuming you have declared fout, the only problem is the confusion between insertion and extraction operators. Use this instead
    Code:
    fout << "Inventory Item 1: " << item1 << endl;

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    ofstream fout;

    meaning fout is ofstream. i declare my own commands sometimes
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    and i used class because i get this error when i made it char

    `class string' used where a `char' was expected
    then with clas si get the other error

    ------

    for the
    Code:
    class MyClass
    {
    //definition
    };
    
    MyClass item1, item2;  //etc, etc.
    i never used classes before i was just trying to get the errors fixed, but wut would take place of //definition
    Last edited by Klinerr1; 07-22-2002 at 12:15 PM.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  6. #6
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    Originally posted by Gabu
    First error:

    You're declaring multiple classes like multiple variables. You can't do that; I have a feeling you didn't mean to use "class".

    Second error:

    You either missed a variable type, or you're trying to set the values of multiple predefined variables all in one line using commas. If it's the first, add the variable type. If it's the second, you need to separate them using semicolons, not commas.

    Third error:

    Assuming "fout" is just a typo specific to here, the first thing is an input operator; it should be an output operator.
    they are all alreayd named at the top where it says class item1 and so fourth

    fout is ofstream

    heres the entire area around error 2

    Code:
    cout << "Choose your characters name." << endl ;
    cin >> player ;
    cout << "Choose what kind of character to be." << endl ;
    cout << "1. Mage 2. Barbarian 3. Warrior 4. Archer" << endl ;
    cin >> charactertype ;
       if (charactertype == 1)
          gold=75, health=100, magic=60, attack=3, aim=7, defence=9, item1=wizardybook, item2=basicstaff, item3=robe, item4=manapotion, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 2)
          gold=75, health=100, magic=0, attack=15, aim=10, defence=15, item1=hatchet, item2=axe, item3=stonesmallshield, item4=leathercloths, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 3)
          gold=75, health=100, magic=9, attack=13, aim=13, defence=11, item1=dagger, item2=mediumsword, item3=bronzesmallshield, item4=bronzeplatewh, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 4)
          gold=75, health=100, magic=9, attack=12, aim=16, defence=11, item1=dagger, item2=arrows, item3=leathercloths, item4=hppotion, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  7. #7
    Registered User Unreg1stered's Avatar
    Join Date
    Jul 2002
    Posts
    25
    PHP Code:
    if (charactertype == 1)
    {
       
    gold=75;
       
    health=100
      
    magic=60;
       ...;

    You nee to add { and } and each item should be ended with ; instead of ,

  8. #8
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Originally posted by Klinerr1
    for the
    Code:
    class MyClass
    {
    //definition
    };
    
    MyClass item1, item2;  //etc, etc.
    i never used classes before i was just trying to get the errors fixed, but wut would take place of //definition
    ok think of a class as an object, the types of data you need to describe that data and the different things that the object can do. The things it can do are member function and the way it is described is through data members. Something whihc might be appropriate for you might be:
    Code:
    class Barbarian
    {
    public:
       Barbarian( );     //default constructor
       ~Barbarian( );  //destructor
    
       //some typical member functions
       void setName( char* name );  //change the name
       char* getName( );   //get the Barbarians name
       void draw( );  //if it is graphical
    
    private:
       char* name;
       int age;
       int experiencePoints;
       int magicPoints
       Weapon currentWeapon;
    };
    
    
    //now you can declare a Barbarian like you would declare an int, eg
    
    Barbarian me;
    me.setName( "endo" )
    There are many other things that could go in here, the possibilities are endless - depends on you really.


    One other thing, change this:

    Code:
    cout << "Choose your characters name." << endl ;
    cin >> player ;
    cout << "Choose what kind of character to be." << endl ;
    cout << "1. Mage 2. Barbarian 3. Warrior 4. Archer" << endl ;
    cin >> charactertype ;
       if (charactertype == 1)
          gold=75, health=100, magic=60, attack=3, aim=7, defence=9, item1=wizardybook, item2=basicstaff, item3=robe, item4=manapotion, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 2)
          gold=75, health=100, magic=0, attack=15, aim=10, defence=15, item1=hatchet, item2=axe, item3=stonesmallshield, item4=leathercloths, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 3)
          gold=75, health=100, magic=9, attack=13, aim=13, defence=11, item1=dagger, item2=mediumsword, item3=bronzesmallshield, item4=bronzeplatewh, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
       else if(charactertype == 4)
          gold=75, health=100, magic=9, attack=12, aim=16, defence=11, item1=dagger, item2=arrows, item3=leathercloths, item4=hppotion, item5=hppotion, item6=hppotion, item7=hppotion, item8=hppotion, item9=hppotion, item10=empty, item11=empty, item12=empty, item13=empty, item14=empty, item15=empty, item16=empty, item17=empty, item18=empty, item19=empty, item20=empty, item21=empty, item22=empty, item23=empty, item24=empty, item25=empty, item26=empty, item27=empty, item28=empty, item29=empty, item30=empty;
    to a switch statement:
    Code:
    switch( charactertype )
    {
    case 1:
       //assign all that stuff for a Mage.
       break;
    
    case 2:
       //assign all that stuff for a Barbarian.
       break;
    
    case 3:
       //assign all that stuff for a Warrior.
       break;
    
    case 4:
       //assign all that stuff for an Archer.
       break;
    
    default:
       break;
    }
    Last edited by endo; 07-22-2002 at 02:36 PM.

  9. #9
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    after seeing i ahve screwed up in a lot of places i am going to rewrite the code. I want d to avoid having more than one line in the if tree but oh well. im gonna do that set to thing.

    thanks for your allls support + examples
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  10. #10
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    wust the difference between the public: and the private: in your class example
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  11. #11
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i need the varibles in that class thing to be noticed before int main(); will it work the same way
    void draw( ); //if it is graphical
    wut does if it is grpahical mean?
    Last edited by Klinerr1; 07-22-2002 at 07:34 PM.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  12. #12
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    error= no match for `ofstream & >> const char[9]'
    line= fout >> "Item 1: " << item1 << endl;

    fout is ofstream

    item 1 is a string type varible holding this data

    item1="dagger";
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  13. #13
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    You have a ">>" where it should be a "<<" there.

  14. #14
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oh **** ur right i hate those out/input operators
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  15. #15
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    wust the difference between the public: and the private: in your class example

    public - Anything has access to the data.
    private - Only member functions of the class have access.
    protected - Only the base class and classes derived from it have acces.

    Eg.[CODE]
    class DOG
    {

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM