[SOLVED] OOP X not declared! :@
Moderator: Coders of Rage
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: OOP X not declared! :@
At first glance I would say remove your forward declarations(your class declarations). I would imagine you're includes would have the same declarations.
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: OOP X not declared! :@
Nah, the issue is that more than one object provides a definition for certain functions, creating weird issues. You can probably solve this by putting "inline" in front of global function declarations that are defined in the header.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: OOP X not declared! :@
I think we were both wrong Ginto8 (although I still don't see why you have all those forward declarations). Plus you wouldn't want to inline a function just to get it to compile, if there's no other solution than inlining a function for no reason then there's something very wrong with your code or your design. You can get this error from a circular include. You're not still including a .cpp file somwhere are you? Are you including Globals.h in any of the header files that you're including in Globals.h? I would advise removing all your forward declarations and all the includes at the end of Globals.h. Why do you have them there anyway? You should only be including files that you need and you should try not to include headers in headers for exactly this reason.Ginto8 wrote:Nah, the issue is that more than one object provides a definition for certain functions, creating weird issues. You can probably solve this by putting "inline" in front of global function declarations that are defined in the header.
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
-
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Mon Feb 21, 2011 2:55 am
- Current Project: Aleios Engine
- Favorite Gaming Platforms: PC, Dreamcast
- Programming Language of Choice: C++
- Location: Melbourne, Australia
Re: OOP X not declared! :@
It says that "bool quit" is already defined in AI.obj, which basically means that this globals.h is being included in multiple files, thus its trying to define an already defined global variable. And its first come first serve.
I believe putting "bool quit" in a .cpp file and using the extern keyword in the .h would be one way of solving it, but im not sure its the most probably way. Other than that im not so sure on how to fix, i dont really span global variables like that too often.
I believe putting "bool quit" in a .cpp file and using the extern keyword in the .h would be one way of solving it, but im not sure its the most probably way. Other than that im not so sure on how to fix, i dont really span global variables like that too often.
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: OOP X not declared! :@
It's not because it's included in multiple files. That wouldn't make any difference since there are #ifndef guards around the header. What use would it be if you couldn't include it in multiple files.Aleios wrote:It says that "bool quit" is already defined in AI.obj, which basically means that this globals.h is being included in multiple files, thus its trying to define an already defined global variable. And its first come first serve.
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
- VoidElite
- Chaos Rift Cool Newbie
- Posts: 54
- Joined: Sun Apr 24, 2011 5:25 am
- Current Project: Lunar Sanity, 2D engine for PC.
- Favorite Gaming Platforms: Playstation
- Programming Language of Choice: C
- Location: England
Re: OOP X not declared! :@
OK guys, my project is fucked up!
Basically I've solved all errors with Skype help from Nico but unfortunately we can't seem to fix this. Basically when I click Build&Run in Visual C++ it's crashing(the game) and giving me a fuck-load of bull shitty exception stuff. When I run the game from outside VC++ it's loading the GFX and all but when I click on it, it crashes.
From VC++ it's giving me some 'Memory access violations' or summet. Anywhoo here's what I could pull together.
It opens the file new.cpp during debugging(source here):
As if that's got something to do with the runtime errors. Also it tell me this about SDL:
Any help because this is WAY out of my expertise?
EDIT: During the VC++ debug phase tells me of a problem at new.cpp, line 59 in which is this segment of the code:
Which if you read the comments appears to say I have no memory if it reaches that code? Me very confuzzled now... :\
Basically I've solved all errors with Skype help from Nico but unfortunately we can't seem to fix this. Basically when I click Build&Run in Visual C++ it's crashing(the game) and giving me a fuck-load of bull shitty exception stuff. When I run the game from outside VC++ it's loading the GFX and all but when I click on it, it crashes.
From VC++ it's giving me some 'Memory access violations' or summet. Anywhoo here's what I could pull together.
It opens the file new.cpp during debugging(source here):
Code: Select all
/***
*new.cxx - defines C++ new routine
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines C++ new routine.
*
*******************************************************************************/
#ifdef _SYSCRT
#include <cruntime.h>
#include <crtdbg.h>
#include <malloc.h>
#include <new.h>
#include <stdlib.h>
#include <winheap.h>
#include <rtcsup.h>
#include <internal.h>
void * operator new( size_t cb )
{
void *res;
for (;;) {
// allocate memory block
res = _heap_alloc(cb);
// if successful allocation, return pointer to memory
if (res)
break;
// call installed new handler
if (!_callnewh(cb))
break;
// new handler was successful -- try to allocate again
}
RTCCALLBACK(_RTC_Allocate_hook, (res, cb, 0));
return res;
}
#else /* _SYSCRT */
#include <cstdlib>
#include <new>
_C_LIB_DECL
int __cdecl _callnewh(size_t size) _THROW1(_STD bad_alloc);
_END_C_LIB_DECL
void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)
{ // try to allocate size bytes
void *p;
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
_RAISE(nomem);
}
return (p);
}
/*
* Copyright (c) 1992-2002 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V3.13:0009 */
#endif /* _SYSCRT */
Note: I've reinstalled VC++ and the SDL headers ext.but somehow it's suddenly fucked up. ;([Frames below may be incorrect and/or missing, no symbols loaded for SDL.dll]
Any help because this is WAY out of my expertise?
EDIT: During the VC++ debug phase tells me of a problem at new.cpp, line 59 in which is this segment of the code:
Code: Select all
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
_RAISE(nomem);
}
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).
I settling into my hybrid(procedural&object orientated) life. It's all good so far.
I settling into my hybrid(procedural&object orientated) life. It's all good so far.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: OOP X not declared! :@
Trade contact info with me and I'll resolve the problem with you.
- VoidElite
- Chaos Rift Cool Newbie
- Posts: 54
- Joined: Sun Apr 24, 2011 5:25 am
- Current Project: Lunar Sanity, 2D engine for PC.
- Favorite Gaming Platforms: Playstation
- Programming Language of Choice: C
- Location: England
Re: OOP X not declared! :@
Do you have Skype if so my name is 'istalkbugs' add me.qpHalcy0n wrote:Trade contact info with me and I'll resolve the problem with you.
Else my email address is marcalexanderreed@hotmail.com.
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).
I settling into my hybrid(procedural&object orientated) life. It's all good so far.
I settling into my hybrid(procedural&object orientated) life. It's all good so far.
-
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Mon Feb 21, 2011 2:55 am
- Current Project: Aleios Engine
- Favorite Gaming Platforms: PC, Dreamcast
- Programming Language of Choice: C++
- Location: Melbourne, Australia
Re: OOP X not declared! :@
I guess i wasn't saying it clearly, or just my sentence sucksMrDeathNote wrote:It's not because it's included in multiple files. That wouldn't make any difference since there are #ifndef guards around the header. What use would it be if you couldn't include it in multiple files.Aleios wrote:It says that "bool quit" is already defined in AI.obj, which basically means that this globals.h is being included in multiple files, thus its trying to define an already defined global variable. And its first come first serve.
The multiple include of the file is fine, but the fact that there is a global in it isn't fine. The #ifndef guards protect against multiple inclusion, but try putting a global in your main.cpp then one in say a file named booltest.cpp
if both have the same name & type, for example bool quit then the compiler will bitch. If your header, lets say booltest.h contains bool quit and you have included this header in main.cpp and booltest.cpp, it will then proceed to bitch since you have basically done what happens with just two .cpp files having the same global.
I hope i said it right this time :S or at least given the basic idea.
For reference:
main.cpp
Code: Select all
bool quit;
int main()
{
return 0;
}
Code: Select all
bool quit;
this is also an issue:
main.cpp
Code: Select all
#include "booltest.h"
int main()
{
return 0;
}
Code: Select all
#include "booltest.h"
//Nothing here
Code: Select all
#ifndef BOOLTEST_H
#define BOOLTEST_H
bool quit;
#endif
Unless there is something i am missing here, im pretty sure that's whats happening :S i could quite possibly be wrong, but this is what im seeing it as.
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: OOP X not declared! :@
Emmm this wouldn't cause a problem unless main included booltest.cpp which I hope you would never do.Aleios wrote: For reference:
main.cppbooltest.cppCode: Select all
bool quit; int main() { return 0; }
ISSUE, Definition of same name and typeCode: Select all
bool quit;
This is an issue, and it was my original thought but I assumed (perhaps incorrectly) that since he's gotten this far he could spot a simple variable redefinition.Aleios wrote: this is also an issue:
main.cppbooltest.cppCode: Select all
#include "booltest.h" int main() { return 0; }
booltest.hCode: Select all
#include "booltest.h" //Nothing here
ISSUE: this will still redefine the globalCode: Select all
#ifndef BOOLTEST_H #define BOOLTEST_H bool quit; #endif
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
-
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Mon Feb 21, 2011 2:55 am
- Current Project: Aleios Engine
- Favorite Gaming Platforms: PC, Dreamcast
- Programming Language of Choice: C++
- Location: Melbourne, Australia
Re: OOP X not declared! :@
ahh good pointMrDeathNote wrote: This is an issue, and it was my original thought but I assumed (perhaps incorrectly) that since he's gotten this far he could spot a simple variable redefinition.
And if i ever did include a .cpp file on purpose, i would request that someone shoot me with a barret .50cal in both of my feet for doing something that would have been overlooked in my early early days.MrDeathNote wrote: Emmm this wouldn't cause a problem unless main included booltest.cpp which I hope you would never do.
And are you sure? unless the way the variables are handled are compiler specific (or even system specific?), it gives out "main.obj : error LNK2005: "bool quit" (?quit@@3_NA) already defined in booltest.obj" under Visual Studio 2010, yet simply changing the bool in main.cpp to a type of int will cause it to compile.
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: OOP X not declared! :@
Fuck! Sorry dude, I misread your code I thought you had the var in a class definition. And yes, i will shoot you if you include a .cpp fileAleios wrote:Unless the way the variables are handled are compiler specific (or even system specific?), it gives out "main.obj : error LNK2005: "bool quit" (?quit@@3_NA) already defined in booltest.obj" under Visual Studio 2010, yet simply changing the bool in main.cpp to a type of int will cause it to compile.
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
- VoidElite
- Chaos Rift Cool Newbie
- Posts: 54
- Joined: Sun Apr 24, 2011 5:25 am
- Current Project: Lunar Sanity, 2D engine for PC.
- Favorite Gaming Platforms: Playstation
- Programming Language of Choice: C
- Location: England
Re: OOP X not declared! :@
Ok guys, just thought I pop in and see WTFbwas going on and...you're still talking...
Basically the code has changed a million times since then and it has long been resolved. Infact I'm progressing quite fast. I just wanted to say thankyou to yall for helping me and goodnight(tomorow I'll set topic to resolved if I remember).
Basically the code has changed a million times since then and it has long been resolved. Infact I'm progressing quite fast. I just wanted to say thankyou to yall for helping me and goodnight(tomorow I'll set topic to resolved if I remember).
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).
I settling into my hybrid(procedural&object orientated) life. It's all good so far.
I settling into my hybrid(procedural&object orientated) life. It's all good so far.