Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error, but I can't spot it

Status
Not open for further replies.

hylian90

MIS
Dec 14, 2004
16
US
Once again, I'm having serious OOP problems. I just compiled a program I've been working on, and got ten errors. I've managed to get it down to two syntax errors, but I can't seem to find them!! I'll post a snippet of the code my compiler is marking as bugged. If you need the WHOLE code, I can give it to you. ::)

Code:
    int Attack()
      {
            cout << "Enemy attacks!" << endl;
            Player.pHP = Player.pHP - ((eAttack * 10) - (Player.pDefend * 5));
      }

Code:
      {
            cout << "Player attacks!!!" << endl;
            Enemy.eHP = Enemy.eHP ((pAttack * 10)-(Enemy.eDefend * 5));
      }

These snippets are methods of the classes Enemy and Player (first is enemy, second is player). These are friendly classes, so they should be able to access each others' variables. It says there is a "syntax error before `;' token" on the lines reassigning Enemy.eHP and Player.pHP, but I can't find one. Do you guys see any syntax errors??[pc3]

--------------------------------------

Code:
//Program to tick off my sister
Programming is officialy a life skill

I have no idea what MIS means
 
C++ isn't really my thing, but
Code:
...Enemy.eHP ((pAttack...
in the second example looks like it needs a plus or a minus in the middle somewhere.
 
>These are friendly classes, so they should be able to access each others' variables.
>Enemy.eHP = Enemy.eHP ((pAttack * 10)-(Enemy.eDefend * 5));

Are you sure `Enemy' is an instance of the class `Enemy', and not the class itself?
From what you said, maybe you are confusing classes and their instances.
If Player is a friend class of Enemy, then the implementation of the class Enemy can access secret features of Player objects.

--
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top