I'm trying to grasp the basics of namespaces, and classes within the namespaces. I was wondering if someone could take a look at my code, and give some pointers on what to do, and what not to do, also a bit on the errors to help mt improve. Thanks.
#include<iostream>
#include "OgreWeaponStrikes.h"
# include<cstdlib>
#include<string>
usingnamespace std;
void OgreWeaponStrikes::OgreSwordStrikes::OgreSwordStrikes()
{
int String;
int RandomNumber;
}
|error: expected unqualified-id before ')' token|
error: return type specification for constructor invalid|
|error: invalid use of incomplete type 'struct OgreWeaponStrikes::OgreSwordStrikes'|
error: forward declaration of 'struct
: 4 errors, 0 warnings ===|
class OgreSwordStrikes() on line 7 of the header, remove ();
Header line 12, Constructors do not have a type. Functions should not share names with the constructors.
#include<iostream>
#include "OgreTitanium.h"
# include<cstdlib>
#include<string>
usingnamespace std;
OgreWeaponStrikes::OgreSwordStrikes::OgreRanSwordStrikes()
{
int String;
int RandomNumber;
return 0;
}
errors
error: expected unqualified-id before ')' token|
error: expected unqualified-id before '{' token|
|error: ISO C++ forbids declaration of 'OgreRanSwordStrikes' with no type|
error: invalid use of incomplete type 'struct OgreWeaponStrikes::OgreSwordStrikes'|
error: forward declaration of 'struct OgreWeaponStrikes::OgreSwordStrikes'|
||=== Build finished: 5 errors, 0 warnings ===|
I'm wondering about
forward declaration of 'struct OgreWeaponStrikes::OgreSwordStrikes'|
If someone can show me how to get this one class working within my namespace, and let me know what's been done wrong, I think I can carry on with all other classes that I want to place within the name space :)
I was able to find one error myself. I had brackets after my class declaration. New sample of code is.
header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef OGREWEAPONSTRIKES_H
#define OGREWEAPONSTRIKES_H
// this namespace is for holding classes and functions dealing with weapon strikes.
namespace OgreWeaponStrikes
{
// Following class deals with swrod strikes
class OgreSwordStrikes
{
//The following method deals with random sword strikes based on OgreSwordStrikeID 1 for light damage, 2 for critical.
//Enemy string passes in the name of the enemy, and DamageAmount passes in the amount of damage done.
public:
int OgreRanSwordStrikes(int OgreSwordStrikesID, int DamageAmount,int EnemyHealth, string EnemyString);
};
CPP
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<iostream>
#include "OgreTitanium.h"
# include<cstdlib>
#include<string>
#include <ctime>
usingnamespace std;
OgreWeaponStrikes::OgreSwordStrikes::OgreRanSwordStrikes(int OgreSwordStrikesID, int DamageAmount, int EnemyHealth, string EnemyString)
{
switch(OgreSwordStrikesID)
that's only partial of the cpp..
errors are.
error: 'string' has not been declared|
error: ISO C++ forbids declaration of 'OgreRanSwordStrikes' with no type|
prototype for 'int OgreWeaponStrikes::OgreSwordStrikes::OgreRanSwordStrikes(int, int, int, std::string)' does not match any in class 'OgreWeaponStrikes::OgreSwordStrikes'|
error: candidate is: int OgreWeaponStrikes::OgreSwordStrikes::OgreRanSwordStrikes(int, int, int, int)|
||=== Build finished: 4 errors, 0 warnings ===|
#ifndef OGREWEAPONSTRIKES_H
#define OGREWEAPONSTRIKES_H
#include<string>
// this namespace is for holding classes and functions dealing with weapon strikes.
namespace OgreWeaponStrikes
{
// 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.
//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 OgreRanSwordStrikesBtl(int OgreSwordStrikesID, int DamageAmount, int EnemyHealth, string EnemyName);
};
}
#endif // OGREWEAPONSTRIKES_
CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
#include "OgreTitanium.h"
# include<cstdlib>
#include<string>
#include<ctime>
usingnamespace std;
//This is the body of code that will be executed when OgreRanSwordStrikes is called.
int OgreSwordStikes::OgreRanSwordStrikesBtl(int OgreSwordStrikesID, int DamageAmount, int EnemyHealth, string EnemyName)
{
return 0;
}
the errors are
error: 'OgreSwordStikes' has not been declared|
error: 'string' has not been declared|
now I have my first workin namespace, and class. I appreciate the help, I've been digging for this for days, had some run ins with some really helpful people like yourself, and a some not so helpful people. Thanks man :)