>main.cpp

#include <cstdlib>
#include <iostream>
using namespace std;

#include "function.h"
       
int main(int argc, char *argv[])
{
    struct AXEMAN{
           int lvl;
           int att;
           int hp;};
    struct DEFENDER{
           int lvl;
           int att;
           int hp;};
    struct ARCHER{
           int lvl;
           int att;
           int hp;};
    struct SPEARMAN{
           int lvl;
           int att;
           int hp;};
    struct ROUGE{
           int lvl;
           int att;
           int hp;};
           
     struct AXEMAN axeman;
     struct DEFENDER defender;
     struct ARCHER archer;
     struct ROUGE  rouge;
     struct SPEARMAN spearman;
     char matrix[70][50];  

    initialize_board(matrix);
    initialize_status_player(axeman, defender, archer, spearman, rouge);

    system("PAUSE");
    return EXIT_SUCCESS;
}

>function.h

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge);
void initialize_board(char matrix[][50]);

>function.cpp

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

void initialize_board(char matrix[][50])
{
     for(int i=0;i<70;i++)
     for(int j=0;j<50;j++)
     {
     matrix[i][j]=' ';
     }
}

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge)
{
     axeman. lvl=1;
     axeman. att=40;
     axeman. hp=450;
     defender. lvl=1;
     defender. att=30;
     defender. hp=500;
     archer. lvl=1;
     archer. att=50;
     archer. hp=300;
     spearman. lvl=1;
     spearman. att=45;
     spearman. hp=400;
     rouge. lvl=1;
     rouge. att=35;
     rouge. hp=350;
}

error log:
Compiler: Default compiler
Building Makefile: "D:\Documents and Settings\kiwi\My Documents\KIWI DOCUMENTS\my program\C++\test\New Folder\Makefile.win"
Executing make clean
rm -f test1.o addition.o show.o Project2.exe

g++.exe -c test1.cpp -o test1.o -I"C:/Program Files/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Program Files/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Program Files/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Program Files/Dev-Cpp/include/c++/3.4.2" -I"C:/Program Files/Dev-Cpp/include"

In file included from test1.cpp:5:
show.h:1: error: variable or field `initialize_status_player' declared void
show.h:1: error: `AXEMAN' was not declared in this scope
show.h:1: error: `axeman' was not declared in this scope
show.h:1: error: `DEFENDER' was not declared in this scope
show.h:1: error: `defender' was not declared in this scope
show.h:1: error: `ARCHER' was not declared in this scope
show.h:1: error: `archer' was not declared in this scope
show.h:1: error: `SPEARMAN' was not declared in this scope
show.h:1: error: `spearman' was not declared in this scope
show.h:1: error: `ROUGE' was not declared in this scope
show.h:1: error: `rouge' was not declared in this scope
show.h:1: error: initializer expression list treated as compound expression

test1.cpp: In function `int main(int, char**)':
test1.cpp:41: error: `initialize_status_player' cannot be used as a function

make.exe: *** [test1.o] Error 1

Execution terminated

Recommended Answers

All 12 Replies

Your structs are declared in main and are therefore out of scope in function.h.
You could fix this defining the structs in function.h

Aside from your scope issue you have 6 identical structs. Inheritance exists for a reason.

struct AXEMAN{
           int lvl;
           int att;
           int hp;};
    struct DEFENDER{
           int lvl;
           int att;
           int hp;};
    struct ARCHER{
           int lvl;
           int att;
           int hp;};
    struct SPEARMAN{
           int lvl;
           int att;
           int hp;};
    struct ROUGE{
           int lvl;
           int att;
           int hp;};

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge);
void initialize_board(char matrix[][50]);

error log:
test1.cpp: In function `int main(int, char**)':
test1.cpp:40: error: invalid initialization of reference of type 'AXEMAN&' from expression of type 'main(int, char**)::AXEMAN'
show.h:22: error: in passing argument 1 of `void initialize_status_player(AXEMAN&, DEFENDER&, ARCHER&, SPEARMAN&, ROUGE&)'

make.exe: *** [test1.o] Error 1

You shouldn't have spaces in between the . and the poperty for one thing. axeman.att , not axeman. att . As a complete side note it's spelled "rogue", "rouge" is makeup. Also, what is in show.h you haven't posted the code. Or test.cpp for that matter.

You shouldn't have spaces in between the . and the poperty for one thing. axeman.att , not axeman. att . As a complete side note it's spelled "rogue", "rouge" is makeup. Also, what is in show.h you haven't posted the code. Or test.cpp for that matter.

i changed axeman.att , not axeman. att . But the error still there.
show.h actually is my function.h. i save show.h in my program. But i post here, i write as function.h.

so function.h is actually show.h and main.cpp is actually test.cpp? Yeah, that's not confusing at all.

yes... sorry for the wrong file name...

You shouldn't have spaces in between the . and the poperty for one thing. axeman.att , not axeman. att ...

Why?!

axeman // this
. // is
att // a legal
= 40; // text

May be I don't understand your statement?

Why?!

axeman // this
. // is
att // a legal
= 40; // text

May be I don't understand your statement?

A) It's annoying, B) It's bad form, C) could break some IDEs, D) Hard to debug (not necessarily in his case but definitely in yours) having a dot on a line by itself.

>function.h

struct AXEMAN{
           int lvl;
           int att;
           int hp;};
    struct DEFENDER{
           int lvl;
           int att;
           int hp;};
    struct ARCHER{
           int lvl;
           int att;
           int hp;};
    struct SPEARMAN{
           int lvl;
           int att;
           int hp;};
    struct ROUGE{
           int lvl;
           int att;
           int hp;};

void initialize_status_player(AXEMAN &axeman, DEFENDER &defender, ARCHER &archer, SPEARMAN &spearman, ROUGE &rouge);
void initialize_board(char matrix[][50]);

error log:
maincpp: In function `int main(int, char**)':
main.cpp:40: error: invalid initialization of reference of type 'AXEMAN&' from expression of type 'main(int, char**)::AXEMAN'
function.h:22: error: in passing argument 1 of `void initialize_status_player(AXEMAN&, DEFENDER&, ARCHER&, SPEARMAN&, ROUGE&)'

make.exe: *** [main.o] Error 1

anyone have idea on this error?

>anyone have idea on this error?
I have no ideas but that's counter-question:
anyone have idea on line main.cpp:40 contents?

>anyone have idea on this error?
I have no ideas but that's counter-question:
anyone have idea on line main.cpp:40 contents?

you mean system("pause"); ?
it just pause it. it is dos command.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.