|
|
int livesPos[] = {30, 15};
the '{' can only be used for variable instantiation and not later.
|
|
|
|
|
|
one good way would be to not have globals. Another would be to use a vector. A third would be
livesPos = new int[2];
livesPos[0] = 5;
livesPos[1] = 666;
or whatever.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
The problem with a global is that you can't debug it, or control it. At a minimum, create a class that has public static methods to get and set variables which are private. That way, you can set breakpoints if you need to debug access to the values. Even better, create a class with protected members, and make the classes you want to grant access, friends of that class.
Lord Kixdemp wrote: you do live here, don't you?
*grin* 14+ hours a day, yeah.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
That is all very nice and true only one problem: this guy said he used C and not C++..
I guess u could some OO implementation in C (header represents a class and each function takes a pointer to structure that represents 'this'), still u don't have encapsulation...
|
|
|
|
|
Oh, I missed that. Then, there's no way around it. C kind of sucks that way.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What would you do without global variables?
|
|
|
|
|
|
Write maintainable code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Maintainable code? What do you mean?
Windows Calculator told me I will die at 28.
|
|
|
|
|
It means, code that is easy to work on if you have to come back to it later.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.
void CNew1Dlg::OnBUTTONPick() <br />
{<br />
CString textSub;<br />
textSub.Format("%d %s", someNumber, someString);<br />
GetDlgItem(someEditBox)->SetWindowText(textSub); <br />
}
|
|
|
|
|
Oliver123 wrote: Is a separate CString textSub instance created each time the function executes?
Of course. You don't need to clean it up, it's not a pointer, it will clean itself up ( calling it's own destructor )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Unless you use a "new " operator explicitly,it gets cleaned up automatically once it looses it's scope (Once it returns back to the caller). If you had used "new " to instantiate the object,then you need to "delete " it mannualy.
Dario: How is "directory" in French? (I mean a file system directory).
John Simmons: "zee file holdaire thingie"
|
|
|
|
|
Another important thing is: sometimes you'll need to call GetBuffer() or another function of that kind, if you do that, you must remember to call also ReleaseBuffer() just before exiting the scope of the CString variable.
Hope this helps
|
|
|
|
|
Hi,
I've got implemented Windows Error Reporting for XP(faultrep.dll, ReportFault, SetUnhandledExceptionFilter), but it's not working for Vista.
Vista has a new DLL(wer.dll) and new API for that(WerReportCreate, WerReportSubmit, WerReportCloseHandle). I've tried search web for some code example, but unsuccesefully.
Is anybody can explain the proper way to implement it with new API or send some code examle.
I'll appreciate any info/code.
Thanks.
|
|
|
|
|
oleg63 wrote: I've tried search web for some code example, but unsuccesefully.
They hide that information in the documentation[^]
led mike
|
|
|
|
|
Thanks Mike for the prompt answer,
I've red that documentation but it's just API description without a real example.
Sometimes you need not just API but the way how to employ it in your application.
|
|
|
|
|
Okay, there's a game, a while loop, and a timer to make the game go at 60FPS
while(timer > 0) {
/* GAME STUFF */
timer--;
}
When the user presses ESC, it calls a function, or method, whatever you wanna call it. Anyway, inside it is a while loop, like this:
while(true) {
if(user clicks yes)
return 1;
if(user clicks no)
return 0;
}
So it will wait forever for the user to do something, i expected this to stop the game. But after selecting no, to continue the game, stuff has still happened. Falling to the floor for example.
The game also has a pause thing in place, so if Paused == true, nothing happens. I tried adding that to the above while loop, game didn't get paused, player still fell to the floor. Leaving me rather confused.
Anyone have any ideas on this? Anything at all.
|
|
|
|
|
The Undefeated wrote: Anyone have any ideas on this? Anything at all.
Yes, it sounds like you need some additional threads to handle the various events going on. With only one thread, it's busy running the game and has no time to handle mouse clicks and such.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
??? But its supposed to stop running the game while the while loop is in action.
The game still semi runs, gravity still carries on, and so does swinging, but some other thing don't, like collision checking. So what ends up happening is, you press ESC, as something is coming towards you, you decide you don't want to quit, and it tells you you just got hit. And all these things are all done after the check for the user pressing ESC as well, so they shouldn't happen at all. Id understand if i was actually using more than one thread, but, im not.
I am using allegro though, thats whats checking keys and the mouse, and the timer, but i'll probably get windows to do the timer later on.
Also when i debug the thing it says it stays in the loop, but stuff still changes.
|
|
|
|
|
Hello,
Just read “Idle Loop Processing” on MFC.
Regrads,
|
|
|
|
|
But i want the app to freeze while it waits...
*sigh* maybe i'll just change it so it works, and never know why this crazy stuff happened.
|
|
|
|