Understanding Pointers

Started by
3 comments, last by clashie 14 years, 2 months ago
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 *'
Advertisement
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.
Here's main:
#include <windows.h>#include "SDL.h"#include "CUtil.h"#include <stdio.h>// Master running boolbool 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.
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'.
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.

This topic is closed to new replies.

Advertisement