Constructor

M

Michael Sgier

Hello
by doing so:
COgroEnemy* ogro = new COgroEnemy;
I call the constructor which should load my model. There i get a syntax
errror. Why?

in oEnemy.h:
class COgroEnemy : public CEnemy // is derived from md.h

{
public:
COgroEnemy() { Load(char* modelFile, char* skinFile); } // here i get:
syntax error before `;' token

~COgroEnemy() {}

void Load(char* modelFile, char* skinFile);
};

in oEnemy.cpp: // is derived from md.h so the md function gets called
void COgroEnemy::Load()
{
// load model
CMD2Model::Load("models\\ogro\\tris.md2", "models\\ogro\\ogrobase.pcx");
}

in md.cpp:
CTexture* CMD2Model::Load(char *modelFile, char *skinFile)
{
....
}

And secondly is that a correct call to CMD2Model::Load in the Load
function? Could I do it otherways? And do
I need the "void Load" declaration in COgroEnemy as i've

in md.h:
// load model and skin/texture at the same time
CTexture* Load(char *modelFile, char *skinFile);

THANKS and regards
Michael
 
J

John Harrison

Michael said:
Hello
by doing so:
COgroEnemy* ogro = new COgroEnemy;
I call the constructor which should load my model. There i get a syntax
errror. Why?

There's no obvious reason why this should be, the line above is
perfectly correct. Check for

1) spelling mistakes
2) you've included the right header file
3) line above this one, sometimes error on the previous line gets
reported on the next line
4) previous errors, sometimes error are caused because you have a
previous error, if you fix the previous error this error might go away

Of course it would help if you quoted the actual error message
in oEnemy.h:
class COgroEnemy : public CEnemy // is derived from md.h

{
public:
COgroEnemy() { Load(char* modelFile, char* skinFile); } // here i
get: syntax error before `;' token

That's because you are getting confused between the syntax for declaring
a function and the syntax for calling a function. If you want to call
the Load function then it is something like this

COgroEnemy() { Load("model_file", "skin_file"); } // here i

When you call a function you just write the value of the parameters

When you declare a function you write the types and names of the parameters

For instance,

int func(int a, int b) // declare func

func(1, 2) // call func
func(x, y) // call func again
~COgroEnemy() {}

void Load(char* modelFile, char* skinFile);
};

in oEnemy.cpp: // is derived from md.h so the md function gets called
void COgroEnemy::Load()

This function does not match what you have in the header file. In the
header file you have two parameters, here you have zero parameters. You
must decide how many you want and stick to it.
{
// load model
CMD2Model::Load("models\\ogro\\tris.md2",
"models\\ogro\\ogrobase.pcx");
}

in md.cpp:
CTexture* CMD2Model::Load(char *modelFile, char *skinFile)
{
...
}

And secondly is that a correct call to CMD2Model::Load in the Load
function?

Only if CMD2Model::Load is a static member function. I can't tell
whether it is or not without seeing the definition of the class CMD2Model.

Could I do it otherways?

Not sure, you wrote the code.

And do
I need the "void Load" declaration in COgroEnemy as i've

in md.h:
// load model and skin/texture at the same time
CTexture* Load(char *modelFile, char *skinFile);

That's depends, Load returns a CTexture*, do you want to do anything
with that object? If you do then you better save the return value
somewhere (maybe in the COgroEnemy class), if not the void is OK. Again
you wrote the code so it is impossible for me to answer this question.
But I think you need to get the syntax errors fixed before addressing
this question.
THANKS and regards
Michael

john
 
V

Victor Bazarov

Kev said:
the missing second ; at the end is a typo?

Are you asking a question? Take another look at the line, what is it
between the curly braces? Is it supposed to be a function call or is
it supposed to be a declaration?

V
 
K

Kev

Are you asking a question? Take another look at the line, what is it
between the curly braces? Is it supposed to be a function call or is
it supposed to be a declaration?

ooops. ;o)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top