Spelling error. You wrote "OgreSwordStikes" instead of "OgreSwordStrikes".
error: 'string' has not been declared|[/quote]
You have two ways to solve it:
- replace string with std::string in the header file.
- import std::string into your own namespace by adding "using std::string;" inside of your namespace in your header file.
well, I got it all down to 1 error. It's the same one. I don't know if I changed something after fixing the typo, or what. I added half the functionality I wanted in the function, so I'll paste the while code, so you can get a closer look.
header #ifndef OGREWEAPONSTRIKES_H
#define OGREWEAPONSTRIKES_H
#include<string>
// this namespace is for holding classes and functions dealing with weapon strikes.
namespace OgreWeaponStrikes
{
using std::string;
// Following class deals with swrod strikes
class OgreSwordStrikes
{
//The following method deals with random sword strikes based on OgreSwordStrikeID. a value of 1 is for light damage, and 2 for critical.
//Enemy string passes in the name of the enemy, and DamageAmount, and EnemyHealth passes in the amount of damage done, as well as enemies health.
//When the code is executed it will subtract damage amount from enemy health, and display a message stating what has been
//for damage, a description of the attack, as well as to whom the damage was done to.
public:
int OgreRanSwordStrikes(int OgreSwordStrikesID, int DamageAmount, int EnemyHealth, string EnemyName);
};
}
#endif // OGREWEAPONSTRIKES_
cpp #include<iostream>
#include "OgreTitanium.h"
# include<cstdlib>
#include<string>
#include<ctime>
using std::string;
using namespace std;
//This is the body of code that will be executed when OgreRanSwordStrikes is called.
int OgreSwordStrikes::OgreRanSwordStrikes(int OgreSwordStrikesID, int DamageAmount, int EnemyHealth, string EnemyName)
{
switch (OgreSwordStrikesID)
{
//random attack display will determine which text will be displayed for the attack message.
Just a note, you don't want to call srand() twice. Call it once at the beginning of your program, then don't touch it. srand() just seeds the random number generator. Once it's been seeded, it's good to go. Reseeding it is unnecessary, and can even give less-random results.
I can only find one place in the code I called it. That was in the switch. I may just be having a blind moment, lol, can ya point it out?
Yes you call it once in the function, but every single time you call the function it will call srand() again. If you call the OgreRanSwordStrikes function only once, its fine. But if you ever plan on calling that function more than once, it's an issue.