Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

GAH! THE FRUSTRATION!


  • Please log in to reply
3 replies to this topic

#1 sausage

sausage

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:02:02 AM

Posted 03 March 2009 - 03:31 AM

what is wrong with the following code?????
#include "Monster.h"
#include "Player.h"
#include "battle.h"
#include <iostream>

Monster::Monster(int Attack,int Defense,int HitPoints,std::string Name,std::string Greeting)
{
				 mAttack = Attack;
				 mDefense = Defense;
				 mHitPoints = HitPoints;
				 mName = Name;
				 mGreeting = Greeting;
				 if(mAttack <= 5)
				 Range = 2;
				 else if(mAttack <= 10)
				 Range = 3;
				 else if(mAttack <= 20)
				 Range = 5;
}
Monster::void Attack()
{
				 Battle.damage = mAttack+(rand()%range);
				 cout << "The";
}
Monster::void Greet()
{
				cout << mGreeting;
}

#include <iostream>
#include "Player.h"
#ifndef MONSTER_H
#define MONSTER_H

class Monster
{
	  public:
	  int mAttack;
	  std::string mName;
	  int mDefense;
	  int mHitPoints;
	  int Range;
	  std::string mGreeting;
	  Monster(int Attack,int Defense,int HitPoints,std::string Name,std::string Greeting);
	  void attack();
	  void hitpointUpdate();
	  void greet();
};
#endif

"Expected Unqualified-id before void" line 20 in Monster.cpp
"Expected Constructor or Destructor or type-conversion before void" line 20
expected ";" or ";" before void line 20
Expected Unqualified-id before void line 25
Expected Constructor or Destructor or type-conversion before void line 25
Expected ";" or ";" before void line 25
[Build Error][Monster.o] Error 1

I am so frustrated!

and please don't harp on me for using all public variables.. I just don't see the point of private variables, it creates more work...

BC AdBot (Login to Remove)

 


#2 jpshortstuff

jpshortstuff

    WhatTheTech Teacher


  • Members
  • 660 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:09:02 AM

Posted 03 March 2009 - 08:25 AM

Your "voids" are in the wrong place, they need to be at the start:

Monster::void Attack()
{
				 Battle.damage = mAttack+(rand()%range);
				 cout << "The";
}
Monster::void Greet()
{
				cout << mGreeting;
}
Should be:
void Monster::Attack()
{
				 Battle.damage = mAttack+(rand()%range);
				 cout << "The";
}
void Monster::Greet()
{
				cout << mGreeting;
}

http://www.cplusplus.com/doc/tutorial/classes.html

Edited by jpshortstuff, 03 March 2009 - 08:25 AM.

Trained at the What The Tech Classroom where you too could learn to help others.

My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here Posted Image

Posted Image

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:02 AM

Posted 03 March 2009 - 08:27 AM

I just don't see the point of private variables, it creates more work...

Because inheritance and polymorphism, which make less work depend on it. You'll figure out why when you start getting mysterious bugs. It also often means that if you decide to refactor the class, you have to rewrite everything that interfaces with it.

EDIT: I see jpshortstuff has you straightened out.

#4 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:02:02 AM

Posted 03 March 2009 - 05:35 PM

Because inheritance and polymorphism, which make less work depend on it. You'll figure out why when you start getting mysterious bugs. It also often means that if you decide to refactor the class, you have to rewrite everything that interfaces with it


Ok, I know how to use them so I'll start doing that

And thanks :-)

Edited by sausage, 03 March 2009 - 05:35 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users