|
Class Problem |
moon_rabbits
Member #8,469
March 2007
|
I am making a game similar to missile defence so that I can become used to Allegro and whatnot. I wrote something up that generates a background and saves it to a bitmap, everything was going good until I added a class in a separate .cpp file.
That's the tank class header and .cpp file. The program compiles fine, but this error is given when it runs: The instruction at "0x10020efc" referenced memory at "0x00000038". The memory could not be "read". Click on OK to terminate the program Help, please? |
Jonatan Hedborg
Member #4,886
July 2004
|
How do you use the class? Make sure you don't create it until you have initiated allegro. Post some more code.
|
moon_rabbits
Member #8,469
March 2007
|
Here is the only other code I have written so far, the main.cpp file:
EDIT: The CTank class is used in the main() function only. |
Matthew Dalrymple
Member #7,922
October 2006
|
There is no semi-colon after END_OF_MAIN() =-----===-----===-----= |
moon_rabbits
Member #8,469
March 2007
|
I removed the semi-colon, the problem persists. |
gnolam
Member #2,030
March 2002
|
Jonatan nailed it. The class's constructor (and thus create_bitmap() etc) is called before Allegro is initialized. -- |
Matthew Dalrymple
Member #7,922
October 2006
|
CTank is declared before Allegro is initialized. The constructor of CTank uses allegro definitions. edit: =-----===-----===-----= |
moon_rabbits
Member #8,469
March 2007
|
Ah! It all makes sense now. Everything is working now, thanks everyone~ |
bamccaig
Member #7,536
July 2006
|
NEVERMIND! (Runs away crying...) {smiley} -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
ImLeftFooted
Member #3,935
October 2003
|
Quote:
/******************** An underscore followed by an uppercase letter is undefined behavior. Adopt a new naming scheme. |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: An underscore followed by an uppercase letter is undefined behavior. Actually, symbols and macros starting with an underscore are reserved for compiler/system use. -- |
ImLeftFooted
Member #3,935
October 2003
|
But the resulting behavior is undefined |
Thomas Fjellstrom
Member #476
June 2000
|
Its perfectly defined. Expect problems when the symbol you chose happens to be used in the compiler or system headers sometime in the future. edit: I used to use _FILENAMEHERE_H_ I now use FileNameHere_H_GUARD
-- |
Tobias Dammers
Member #2,604
August 2002
|
Quote: An underscore followed by an uppercase letter is undefined behavior. No, it's definitely not. An identifier in C can start with any letter (upper- or lowercase), or an underscore, and after that, it can contain letters, underscores, and numeric digits. Quote: Actually, symbols and macros starting with an underscore are reserved for compiler/system use. Double underscores. Single underscores should be fine. Quote: But the resulting behavior is undefined
Not at all. #ifndef __FILE__ #define __FILE__ // anything here will be ignored, because __FILE__ is always defined #endif ...or it will produce compiler errors due to incompatible definitions for the identifier. Neither of these constitute undefined behaviour. --- |
Onewing
Member #6,152
August 2005
|
Quote: I used to use _FILENAMEHERE_H_ I now use FileNameHere_H_GUARD Interesting... I've been using the top method since the beginning as that was the way I was taught. Never seen a problem... ------------ |
bamccaig
Member #7,536
July 2006
|
I could be wrong, but I assumed it wasn't a compiler rule, but a good practice. Like root declaring environment variables in all CAPS (or was it the other way around) in a *nix environment. I think it's only a problem if that identifier is already defined, such as _FILE_. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
ImLeftFooted
Member #3,935
October 2003
|
Quote: Double underscores. Single underscores should be fine. Single underscores followed by an uppercase letter are reserved for compiler usage. Quote: Its perfectly defined. Expect problems when the symbol you chose happens to be used in the compiler or system headers sometime in the future. Technically the C++ spec does not define if you will collide or not, and when that collision occurs the results are compiler specific and therefore undefined. I agree with you , I was just saying undefined to make my sentence more english and less codelish. |
|