C++ NEWB QUESTION: char array into a function

Started by
9 comments, last by Evil Steve 17 years, 5 months ago
I'm trying to pass a char array into a function. Does anyone know why this isn't working?

// Part of Mower.h

void Mower::loadSound(HGE &hge, char sndFile[])
{
	snd2 = hge.Effect_Load(sndFile); // must pass the char sequence here.
}
//-------------- //-------------- Then here is what I have in my main() function.

Mower gMower = new Mower();
gMower.loadSound((*hge), "sndMower.wav");// must send this char array                                                       
                                        // to above function
Advertisement
Define "not working".
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Do you mean that it won't compile or that it doesn't do what you expect? Try printing out the value of the array inside the method... And if the Effect_Load() method requires a const char* use const char for the loadSound() as well...
The usual way is to use a const char*:
void Mower::loadSound(HGE &hge, const char* sndFile){   snd2 = hge.Effect_Load(sndFile); // must pass the char sequence here.}gMower.loadSound((*hge), "sndMower.wav");
I looked up the documentation on Effect_Load and here it is:

HEFFECT Effect_Load(  const char *filename,  DWORD size = 0);


So I used:

void Mower::loadSound(HGE &hge, const char* sndFile){   snd2 = hge.Effect_Load(sndFile); // must pass the char sequence here.}gMower.loadSound((*hge), "sndMower.wav");


as you said, and Still got the error.

Quote:
error C2511: 'void Mower::loadSound(HGE &,const char *)' : overloaded member function not found in 'Mower'

I looked up the documentation on Effect_Load and here it is:

HEFFECT Effect_Load(  const char *filename,  DWORD size = 0);


So I used:

void Mower::loadSound(HGE &hge, const char* sndFile){   snd2 = hge.Effect_Load(sndFile); // must pass the char sequence here.}gMower.loadSound((*hge), "sndMower.wav");


although the sound is still not loading


The only problem I see in your code so far is in here:
Mower gMower = new Mower();gMower.loadSound((*hge), "sndMower.wav");// must send this char array                                                                     // to above function


The new operator returns a pointer to a new object of type Mower but your gMover variable is no pointer. Maybe only a typo :D



edit : If this is indeed the mistake it should be :
Mower *gMower = new Mower();gMower->loadSound((*hge), "sndMower.wav");// must send this char array                                                                     // to above function
Antimon Antimon Antimoooooon
Quote:Original post by Instigator
Quote:
error C2511: 'void Mower::loadSound(HGE &,const char *)' : overloaded member function not found in 'Mower'
That means that the function declaration in your class declaration (Which should be in the class header) doesn't match the version you have in the source file.
Okay I fixed what you guys told me to do: So thanks for your help :D


However, now i'm just using Mower as a global object. by doing:

Mower gMower(10); // it's global not a pointer
int test = 0;

Then I checked to see what was causing the problem by printing the value to the screen. I printed it with a MessageBox(); and realized that the string was indeed what is what supposed to be. Therefore, the problems obviously something else. Later on in the program I did a test on that sound handle and it returns 'null'. So I'm guessing someone where in my program there's a problem. I'll reply back when I have an idea.

Thank you guys. At least I know it's not the char sequence anymore :)
Finally figured it out. Stupidest mistake I've ever made. Visual Studio 2005 can really piss me off sometimes. This is why this happened:

I loaded that string called "Mower.wav" into a soundEffect (with my game engine). And I was wondering why it kept saying that the file hasn't loaded into the variable.

I finally figure out that Visual Studios 2005 checks for the "Mower.wav" file in the weirdest place. Why can't it just check in the root of where your project is located? Can someone to me the logic behind this?

My workspace for this project was something like

"C:\documents\visualStudio2005\projects\ThisprojectName"

VS 2005 created 3 subdirectories.

"C:\documents\visualStudio2005\projects\ThisProjectName\ThisProjectName\debug"

Note: 'ThisProjectName'inside the original projectName.

What is the point to creating another directory within the directory of the same name then creating a separate debug folder (even though there's a debug folder in the original folder.

What were they thinking?

Do you VS 2005 owners like this?

This topic is closed to new replies.

Advertisement