Why are there these redefinition bugs?
Why are there these redefinition bugs?
Hi everyone,
I'm programming a game myself with the skills I learnt from Chili.
But now, I have some annoying errors and I don't know how to deal with them. According to stackoverflow the erros occur because of some header-linking things.
Hope you can help me and thx in advance!
misterchi
I'm programming a game myself with the skills I learnt from Chili.
But now, I have some annoying errors and I don't know how to deal with them. According to stackoverflow the erros occur because of some header-linking things.
Hope you can help me and thx in advance!
misterchi
- Attachments
-
- MyGame.zip
- (22 Bytes) Downloaded 112 times
- SlevinKelevra
- Posts: 80
- Joined: September 9th, 2013, 12:58 am
- Location: Germany
Re: Why are there these redefinition bugs?
If you make a new header file and include say, Game.h in it, and include that new file in Game.h as well, you'll get errors., if thats the case.
Or maybe you are making a variable, say int x (or something) in UpdateModel() for instance, then make another variable int x somewhere else in UpdateModel(), that'll make errors as well.
Or maybe you are making a variable, say int x (or something) in UpdateModel() for instance, then make another variable int x somewhere else in UpdateModel(), that'll make errors as well.
Curiosity killed the cat, satisfaction brought him back
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Why are there these redefinition bugs?
If it's the macro redefinitions, _WINNT_WIN32, STRICT and so on, it's because of the way chili has setup the framework. He has a bunch of #defines in ChiliWin.h and any time you include say Graphics.h in another file, ChiliWin.h is included in the list of headers. So each time that file is included, it tries to redefine those macros. The other thing would be if you #include <Windows.h> as well, you'll get the same result.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Why are there these redefinition bugs?
Another reason for redefinition errors, it creating a variable or a function in the header file outside of a class. For functions that don't belong to a class, you have to use the inline keyword
If you are declaring a variable in the header outside of a class, then it must be static or extern.
Another thing might be that you forgot to add #pragma once at the top of the header file.
Code: Select all
inline void Function(params)
{
return;
}
Code: Select all
// SomeHeader.h
static int a;
extern int b;
// SomeSource.cpp
int a = 0;
int b = 0;
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Why are there these redefinition bugs?
There was a little problem with the framework. The way it is setup, "ChiliWin.h" should be included before any other windows headers. But in graphics.h I include the D3D header first, and that can cause problems. The fix is to include "ChiliWin.h" at the top of "Graphics.h"
I do this in the latest version of the framework on GitHub.
I do this in the latest version of the framework on GitHub.
Chili
Re: Why are there these redefinition bugs?
Ok, I found the bug. Now it's fixed. Thx