"Identifier not found" C++ SDL. Help please?

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

Post Reply
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

"Identifier not found" C++ SDL. Help please?

Post by PaperDuckyFTW »

Heya *waves spastically*

A few weeks ago i made a topic asking help on a tile map system. I couldnt get any collision working so i decided jsut to go the hard way and impliment Lazy Foo's tilemap from his tutorial. So far my computer hasnt exploded so thats a good thing, but when i build it i get 2 errors:

error C3861: 'check_collision': identifier not found
error C3861: 'draw_surface': identifier not found

I looked up google for a solution but i found nothing so i thought you guys might have come accorss a simplar problem or know what im doing wrong. so far i have these files:

Code: Select all

main.cpp ( includes all the header files )
variables.h ( includes SDL.h, <string> and <fstream> )
functions.h  ( includes variables.h and classTile.h )
classTimer.h ( includes SDL.h and functions.h )
classPlayer.h ( includes SDL.h, functions and classTimer
classTile.h ( includes variables or functions, ive tried both and each singularly )
All of the header files have #ifndef, #define and #endif to declare them. I dont really know why i am getting that error and if you can help me, i would appreciate it. Have a nice day =]
User avatar
ultimatedragoon69
Chaos Rift Regular
Chaos Rift Regular
Posts: 122
Joined: Tue Oct 28, 2008 1:57 pm
Current Project: Pangea's quest (text ~tile~ based rpg)
Favorite Gaming Platforms: Dreamcast, PC, playstation 1, Virtual Boy, Snes
Programming Language of Choice: c++
Contact:

Re: "Identifier not found" C++ SDL. Help please?

Post by ultimatedragoon69 »

should your draw_surface be apply_surface? did you include the functions into your code? It might help to see the code your having a problem with.
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

Re: "Identifier not found" C++ SDL. Help please?

Post by PaperDuckyFTW »

thanks for your reply and sure. oh the draw_surface function is exactly the same as the apply_surfae, but i prefer it as draw because i dont think of it as applying, and i would refer to it as drawing

heres the parts of the ode thats cocking up. The errors are both in the tile class file.

Code: Select all

void Tile::draw()
{
	if( check_collision( camera, box ) == true )
	{
		draw_surface( box.x - camera.x, box.y - camera.y, tileSheet, screen, &clips[ type ] );
	}
}
Both the check collision and draw surfae functions in this function is what is coming up as unidentified. Both work in all the other files the function.h file is included it except the tile file.
I hope this can help you guys think of what could be wrong
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

Re: "Identifier not found" C++ SDL. Help please?

Post by Maevik »

can you provide more info on how the functions are declared? are they just stand alone functions in functions.h or are they part of a class? if they are just functions, are you including the functions.h header file? do you have a circular include? is there a scope resolution operator you are missing? are they part of a namespace?
My love is like a Haddoken, it's downright fierce!
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

Re: "Identifier not found" C++ SDL. Help please?

Post by PaperDuckyFTW »

okay heres the functions in the functions.h file that arent woking in the tile class

Code: Select all

void draw_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
	SDL_Rect pos;
	pos.x = x;
	pos.y = y;
	
	SDL_BlitSurface( source, clip, destination, &pos );
}

Code: Select all

bool check_collision( SDL_Rect A, SDL_Rect B )
{
    //The sides of the rectangles
    int leftA, leftB;
    int rightA, rightB;
    int topA, topB;
    int bottomA, bottomB;

    //A's rect
    leftA = A.x;
    rightA = A.x + A.w;
    topA = A.y;
    bottomA = A.y + A.h;
        
    //B's rect
    leftB = B.x;
    rightB = B.x + B.w;
    topB = B.y;
    bottomB = B.y + B.h;

    //if the rects are sexually interwined
    if( bottomA <= topB )
    {
        return false;
    }
    
    if( topA >= bottomB )
    {
        return false;
    }
    
    if( rightA <= leftB )
    {
        return false;
    }
    
    if( leftA >= rightB )
    {
        return false;
    }
    
    //If none of the sides from A are outside B
    return true;
}
The functions are not part of any class.
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

Re: "Identifier not found" C++ SDL. Help please?

Post by Maevik »

If I understand correctly, then your problem is definitely a circular include. The error you are getting is trying to call draw_surface and check_collision from the Tile Class (classTile.h)

functions.h includes classTile.h and classTile.h includes functions.h. I know you said it also fails if you include variables.h instead, but this obviously gives you the same error since without functions.h it still doesn't know wtf draw_surface and check_collision are.

What you need to do is design your system so that you are only using singular dependency. I would think that the easiest way to do this with what you have is to make functions.h operate without needing classTile.h.

Good Luck and I hope this helps!
My love is like a Haddoken, it's downright fierce!
PaperDuckyFTW
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 76
Joined: Sat Apr 03, 2010 5:08 am
Programming Language of Choice: C++

Re: "Identifier not found" C++ SDL. Help please?

Post by PaperDuckyFTW »

Hey man thanks for your reply. Your 1 Billion % right. Functions.h and tile.h both include each other and i thought this might be a problem but wasnt to sure. I'll knuckle down and think of how i can make either one included without the other. Yerr, ill try and fix it, sorry if that previous sentance made no sense. Btw, what are you working on? Sorry monds if thiws is off topic. Thanks, ill see if i can get it working
User avatar
Maevik
Chaos Rift Junior
Chaos Rift Junior
Posts: 230
Joined: Mon Mar 02, 2009 3:22 pm
Current Project: www.keedepictions.com/Pewpew/
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Long Beach, CA

Re: "Identifier not found" C++ SDL. Help please?

Post by Maevik »

PaperDuckyFTW wrote:Hey man thanks for your reply. Your 1 Billion % right. Functions.h and tile.h both include each other and i thought this might be a problem but wasnt to sure. I'll knuckle down and think of how i can make either one included without the other. Yerr, ill try and fix it, sorry if that previous sentance made no sense. Btw, what are you working on? Sorry monds if thiws is off topic. Thanks, ill see if i can get it working
Awesome! Glad you got it figured out. What am I working on? I'm working on a small 2D shoot-em-up game. This is the thread if you want to check it out.
My love is like a Haddoken, it's downright fierce!
Post Reply