-
extern struct...
Alright...I searched the boards...and thought I had found what i was looking for...but it didnt quite work...so i tried this...and tried that...still no luck...
Code:
//Pracitce Game
//PracGame2.cpp
#include<iostream>
#include<windows.h>
#include<string>
#include<stdlib.h>//rand()
#include<fstream>//file i/o
#include<basicf.h>//for clrscr();
#include<color.h>//for color definition
#include<time.h>//for time
#include"GMS.h"//for struct define...
using namespace std;
int main()
{
cout<<e1->PEN_NME<<endl;
return 0;
}
////////////////////////////GMS.h//////////////////////
//resource...
//GMS.h
#include<iostream>
#include<windows.h>
using namespace std;
struct Enemy
{
int MX_ATT;//max attack
int MN_ATT;//min attack
int MX_DEF;//max defense
int MN_DEF;//min defense
int MX_HP;//max hp
int MN_HP;//min hp
int T_TRN;//total turns
int R_TRN;//remaining turns
char *PEN_NME;//enemy name
};
Enemy Elias;
Enemy *e1;
Elias.PEN_NME=("Elias of Lithel");
e1=&Elias;
All i want is to be able to define all of the variables in the structure under many different names...this is a somewhat simplified version of the code...but if someone could help I would greatly appreciate it...
-
Code:
struct foo
{
union
{
int name1,name2,name3;
};
};
Here, all three variable names are interchangeable.
-
uhm...i dont really know anything about unions...but Im not sure if I explained myself well enough...
struct Enemy; is going to have alot...and I mean alot of different definitions...and I dont want them in 'int main()'...it would be nice if I could have a seperate file for them...I tried using 'extern'...but I couldnt get it to do exactly what I needed it to...
-
well since no one rushed to my aid ;P (heh j/k)
Ill just go with uploading all of the enemys into a predefined number of struct pointers and what not...
thx anyways~
-
Maybe this is what you need? Is the problem you are having in trying to access the e1 pointer from within the main function?
Code:
//Pracitce Game
//PracGame2.cpp
#include<iostream>
#include<windows.h>
#include<string>
#include<cstdlib>//rand()
#include<fstream>//file i/o
#include<basicf.h>//for clrscr();
#include<color.h>//for color definition
#include<ctime>//for time
#include"GMS.h"//for struct define...
using namespace std;
extern ENEMY* e1;
int main()
{
cout<<e1->PEN_NME<<endl;
return 0;
}
-
nope didnt work =(
Code:
Compiling...
PracGame2.cpp
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2143: syntax error : missing ';' before '.'
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2501: 'Elias' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2371: 'Elias' : redefinition; different basic types
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(40) : see declaration of 'Elias'
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2143: syntax error : missing ';' before '.'
c:\program files\microsoft visual studio\myprojects\pracgame2\pracgame2.cpp(27) : error C2374: 'El1' : redefinition; multiple initialization
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(41) : see declaration of 'El1'
Error executing cl.exe.
PracGame2.exe - 5 error(s), 0 warning(s)
i mean...geez there has to be a way to do this...I just cant figure it out...thx for the try though =/
<b>edit:</b>
the pointer is now El1...because e1 is taken up doing something else now...
-
Try changing this:
Elias.PEN_NME=("Elias of Lithel");
To this:
Elias.PEN_NAME="Elias of Lithel";
And see how you fare.
-
well that did pull off one warning...but gah...still no luck!!
Code:
Compiling...
PracGame2.cpp
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2143: syntax error : missing ';' before '.'
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2501: 'Elias' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2371: 'Elias' : redefinition; different basic types
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(40) : see declaration of 'Elias'
c:\program files\microsoft visual studio\myprojects\pracgame2\gms.h(42) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.
PracGame2.exe - 4 error(s), 0 warning(s)
:( :confused: :(