Re: OOP X not declared! :@
Posted: Tue May 10, 2011 3:47 am
At first glance I would say remove your forward declarations(your class declarations). I would imagine you're includes would have the same declarations.
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
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.
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.
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]
Code: Select all
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
_RAISE(nomem);
}
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.
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.
Code: Select all
bool quit;
int main()
{
return 0;
}
Code: Select all
bool quit;
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
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
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.
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.