I''m working on a Console Arena game, and I''ve run into a problem...
I have these files in my project.
CItem.H CItem.CPP
CCreature.H CCreature.CPP
Globals.H Globals.CPP
BM.H BM.CPP
EQ_List.H EQ_List.CPP
Function.H Function.CPP
The CItem Files are the ones causing me problems. Class CItem is a BASE class with CWeapon, CArmor, and CShield derived from it. For now I''m just working with CWeapon. You can ignore the other two.
I know the code below isn''t the most efficient way to do what I''m doing, but I want to learn it this way for now. So bare with me.
CItem and CWeapon Declaration
class CItem
{
public:
CItem();
CItem(char* a_name, int a_weight, int a_value);
char* name;
int weight;
int value;
};
class CWeapon : public CItem
{
public:
CWeapon();
CWeapon(char* a_name, int a_weight, int a_value, int a_dmg, int a_chancetohit);
int dmg;
int chancetohit;
};
//
//AND THE FUNCTIONS FROM THE .CPP
//
CItem::CItem(char* a_name, int a_weight, int a_value)
{
name = a_name;
weight = a_weight;
value = a_value;
}
CItem::CItem()
{}
CWeapon::CWeapon()
{}
CWeapon::CWeapon(char* a_name, int a_weight, int a_value, int a_dmg, int a_chancetohit)
{
CItem::CItem(a_name, a_weight, a_value);
dmg = a_dmg;
chancetohit = a_chancetohit;
}
Now for the Problem... I''m wanting to Initialize my Weapons from a list, and I have it setup like this.
This is from EQ_List.H and EQ_List.CPP
//EQ_LIST.H
//Defines Extern Global
#include "globals.h"
extern CWeapon *WeaponList;
//END
//EQ_LIST.CPP
//Sets up the Equipment Lists
#include "CCreature.h"
#include "CItem.h"
#include "eq_list.h"
CWeapon *WeaponList = new CWeapon[5];
WeaponList[0] = CWeapon("Rusty Dagger", 1, 1, 3, 0);
WeaponList[1] = CWeapon("Dagger", 1, 5, 4, 0);
WeaponList[2] = CWeapon("Chipped Shortsword", 3, 10, 5, 0);
WeaponList[3] = CWeapon("Shortsword", 3, 25, 6, 0);
WeaponList[4] = CWeapon("Tarnished Longsword", 5, 50, 7, 0);
delete [] WeaponList; //Wouldn''t normally be here, but I''m just testing.
Now, when I try to compile this with the rest of my program, I get a bunch of errors. See Below...
C:\My Documents\Cpp\Battle Masters\eq_list.cpp(12) : error C2466: cannot allocate an array of constant size 0
C:\My Documents\Cpp\Battle Masters\eq_list.cpp(12) : error C2501: ''WeaponList'' : missing storage-class or type specifiers
C:\My Documents\Cpp\Battle Masters\eq_list.cpp(12) : error C2372: ''WeaponList'' : redefinition; different types of indirection
c:\my documents\cpp\battle masters\eq_list.h(7) : see declaration of ''WeaponList''
C:\My Documents\Cpp\Battle Masters\eq_list.cpp(12) : error C2440: ''initializing'' : cannot convert from ''class CWeapon'' to ''int [1]''
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\My Documents\Cpp\Battle Masters\eq_list.cpp(14) : error C2466: cannot allocate an array of constant size 0
There are more, but they are mostly repeats of this. The one that REALLY throws me is the first. "Cannot allocate an array of constant size 0"... I looked this up on MSDN and for some reason it thinks that WeaponList[0] = .... is trying to redefine an array of size zero, when actually I''m trying to set array member 0 to the Cweapon as above..
Gah, I hope this at least makes a little sense. I set this up in a different file and it compiled but when I went back to my original program and went through it line by line it just doesn''t work.... Any Suggestions?
~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~