[SOLVED] OOP X not declared! :@

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
MrDeathNote
ES Beta Backer
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! :@

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
User avatar
Ginto8
ES Beta Backer
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! :@

Post 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.
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.
User avatar
MrDeathNote
ES Beta Backer
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! :@

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
Aleios
Chaos Rift Cool Newbie
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! :@

Post 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.
Image
User avatar
MrDeathNote
ES Beta Backer
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! :@

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
User avatar
VoidElite
Chaos Rift Cool Newbie
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! :@

Post 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... :\
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. :)
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OOP X not declared! :@

Post by qpHalcy0n »

Trade contact info with me and I'll resolve the problem with you.
User avatar
VoidElite
Chaos Rift Cool Newbie
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! :@

Post 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. :)
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. :)
Aleios
Chaos Rift Cool Newbie
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! :@

Post 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.
Image
User avatar
MrDeathNote
ES Beta Backer
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! :@

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
Aleios
Chaos Rift Cool Newbie
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! :@

Post 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.
Image
User avatar
MrDeathNote
ES Beta Backer
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! :@

Post 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 ;)
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"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
User avatar
VoidElite
Chaos Rift Cool Newbie
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! :@

Post 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). :)
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. :)
Post Reply