Jump to content
  • Advertisement
Sign in to follow this  
Instigator

C++ NEWB QUESTION: char array into a function

This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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");

Share this post


Link to post
Share on other sites
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'

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!