Page 4 of 4

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 3:47 am
by MrDeathNote
At first glance I would say remove your forward declarations(your class declarations). I would imagine you're includes would have the same declarations.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 7:45 am
by Ginto8
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.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 9:06 am
by MrDeathNote
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.
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.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 9:37 am
by Aleios
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.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 10:13 am
by MrDeathNote
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.
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.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 12:12 pm
by VoidElite
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):

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 */

As if that's got something to do with the runtime errors. Also it tell me this about SDL:
[Frames below may be incorrect and/or missing, no symbols loaded for SDL.dll]
Note: I've reinstalled VC++ and the SDL headers ext.but somehow it's suddenly fucked up. ;(

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);
                }
Which if you read the comments appears to say I have no memory if it reaches that code? Me very confuzzled now... :\

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 12:53 pm
by qpHalcy0n
Trade contact info with me and I'll resolve the problem with you.

Re: OOP X not declared! :@

Posted: Tue May 10, 2011 1:04 pm
by VoidElite
qpHalcy0n wrote:Trade contact info with me and I'll resolve the problem with you.
Do you have Skype if so my name is 'istalkbugs' add me. :)

Else my email address is marcalexanderreed@hotmail.com. :)

Re: OOP X not declared! :@

Posted: Wed May 11, 2011 2:43 am
by Aleios
MrDeathNote wrote:
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.
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.
I guess i wasn't saying it clearly, or just my sentence sucks :)

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;
}
booltest.cpp

Code: Select all

bool quit;
ISSUE, Definition of same name and type

this is also an issue:

main.cpp

Code: Select all

#include "booltest.h"

int main()
{
return 0;
}
booltest.cpp

Code: Select all

#include "booltest.h"

//Nothing here
booltest.h

Code: Select all

#ifndef BOOLTEST_H
#define BOOLTEST_H

bool quit;

#endif
ISSUE: this will still redefine the global

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.

Re: OOP X not declared! :@

Posted: Wed May 11, 2011 3:08 am
by MrDeathNote
Aleios wrote: For reference:

main.cpp

Code: Select all

bool quit;

int main()
{
return 0;
}
booltest.cpp

Code: Select all

bool quit;
ISSUE, Definition of same name and type
Emmm this wouldn't cause a problem unless main included booltest.cpp which I hope you would never do.
Aleios wrote: this is also an issue:

main.cpp

Code: Select all

#include "booltest.h"

int main()
{
return 0;
}
booltest.cpp

Code: Select all

#include "booltest.h"

//Nothing here
booltest.h

Code: Select all

#ifndef BOOLTEST_H
#define BOOLTEST_H

bool quit;

#endif
ISSUE: this will still redefine the global
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.

Re: OOP X not declared! :@

Posted: Wed May 11, 2011 3:49 am
by Aleios
MrDeathNote 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.
ahh good point
MrDeathNote wrote: Emmm this wouldn't cause a problem unless main included booltest.cpp which I hope you would never do.
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.
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.

Re: OOP X not declared! :@

Posted: Wed May 11, 2011 5:19 am
by MrDeathNote
Aleios 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.
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 file ;)

Re: OOP X not declared! :@

Posted: Sat May 14, 2011 7:12 pm
by VoidElite
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). :)