Sign in to follow this  
Drakk

Understanding Pointers

Recommended Posts

I'm new to C++, and I'm still stuck on pointers. Somewhat. The little that I know, would this be possible? I want to send 'Running' to the function "UTIL_CrashProgram" and have that function set 'Running' to false. File: UTIL.h
#ifndef _INCLUDE_H_UTIL
#define _INCLUDE_H_UTIL

// Basic error function
void UTIL_CrashProgram( const char *Reason, bool Dump2File = false, bool *SendRunningBoolHere = true );

#endif
File: Main.cpp
int main( int argc, char* args[] )
{
	// Crash it
	UTIL_CrashProgram("Failed",false,Running);
	return 0;
}
And last: File: Util.cpp
#include "CUtil.h"

void UTIL_CrashProgram( const char Reason, bool Dump2File, bool *SendRunningBoolHere )
{
	SendRunningBoolHere = false;
}
But when I compile, i get the error:
1>c:\users\drak\desktop\editing\mygreatgamev1\mygreatgamev1\cutil.h(11) : error C2548: 'UTIL_CrashProgram' : missing default parameter for parameter 3
1>c:\users\drak\desktop\editing\mygreatgamev1\mygreatgamev1\cmain.cpp(14) : error C2664: 'UTIL_CrashProgram' : cannot convert parameter 3 from 'bool' to 'bool *'

Share this post


Link to post
Share on other sites
Would you be able to post the code in its entirety, specifically the main.cpp file? It'd be easy enough to offer some comments as is, but it'd be a little easier to offer useful feedback if we could see the whole program.

Share this post


Link to post
Share on other sites
Here's main:

#include <windows.h>
#include "SDL.h"
#include "CUtil.h"
#include <stdio.h>

// Master running bool
bool Running = false;

// Defines
#define MEDIA_DIR "Media"

int main( int argc, char* args[] )
{
printf("Running: %s\n",Running == true ? "Yes" : "No");
UTIL_CrashProgram("Crash",false,Running);
printf("Running2: %s\n",Running == true ? "Yes" : "No");
system("pause");
return 0;
}


All the other files (Util.h/.cpp) are posted fully above.

Share this post


Link to post
Share on other sites
Your error is telling you that it can't convert a 'bool' to a 'bool*' on the third parameter. It means just that. Your 3rd parameter is a bool pointer, 'bool *SendRunningBoolHere'. You attempt to give it a default parameter of 'true'. Well, 'true' isn't of type 'bool*', it's of type 'bool'.

Share this post


Link to post
Share on other sites
Your error message is about as descriptive as you can get, you're trying to pass a bool when it expects a bool*.

You could just prefix 'Running' with a & to signify that you're passing it by address. Set a breakpoint there and check out what happens.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this