Hiya!

Im not new to programming but sometimes i can be really noobie so im sure this is probably really silly. I have an undecleared indentifier that only shows up in the main but is fine in the header and cpp files. I thought it might be an include loop but it doesnt seem to be. It can find the draw function but not its parameter. What have i forgotten?

Creature.h

#ifndef CREATURE_H
#define CREATURE_H
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <string>
using std::string;

class Creatures
{
private:
    int xPos;
    int yPos;;
    ALLEGRO_BITMAP* sprite;

public:
    Creatures(int x, int y, string s); // constructor

    void draw(ALLEGRO_BITMAP* s);   
};

#endif

Creature.cpp

#include "Creatures.h"
#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

Creatures::Creatures(int x, int y, string s)
{
    xPos = x;
    yPos = y;
    sprite = al_load_bitmap(s.c_str());
}

void Creatures::draw(ALLEGRO_BITMAP* s)
{
    al_convert_mask_to_alpha(s, al_map_rgb(255,0,255));
    al_draw_bitmap(s, getX(), getY(), 0);
}

Player.h (astroid and enemy are the same so i didnt include them)

#ifndef PLAYER_H
#define PLAYER_H
#include "Creatures.h"

class Player:public Creatures
{
private:

public:
    Player(int x, int y, string s); //constructor
};

#endif

Player.cpp (astroid and enemy are the same so i didnt include them either)

#include "Player.h"
#include "Creatures.h"

Player::Player(int x, int y, string s):Creatures(x, y, s)
{
}

main

#include <iostream>
#include <conio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include "Player.h"
#include "Enemy.h"
#include "Astroid.h"

int main()
{
    //create objects
    Player* player = new Player(50, 50, "Assets/playerSprite.bmp");
    Enemy* enemy = new Enemy(100, 100, "Assets/enemySprite.bmp");
    Astroid* astroid = new Astroid(200, 200, "Assets/astroidSprite.bmp");

    while(!keys_pressed[KEY_ESCAPE])
    {
        player->draw(s); //errors are these 3 lines, s is an undeclared identifier
        enemy->draw(s);
        astroid->draw(s);
    }

    //destroy stuff
    al_destroy_display(display);
    getch();
    return 0;
}
}

errors

Error   1   error C2065: 's' : undeclared identifier

I only included what i thought was relevant so tell me if you need more info.

player->draw(s); //errors are these 3 lines, s is an undeclared identifier

So where is s defined?

Is creature.h spelled "creature.h" or "creatures.h" -- your program contains both spellings.

In the creature constructor here

Creatures(int x, int y, string s);

then the filename is converted into a string

Creatures::Creatures(int x, int y, string s) //s comes through here
{
    xPos = x;
    yPos = y;
    sprite = al_load_bitmap(s.c_str()); //converted here
}

which then is inherited into player

Player::Player(int x, int y, string s):Creatures(x, y, s)
{
}

and the bitmap filename comes from here

    Player* player = new Player(50, 50, "Assets/playerSprite.bmp");

at least thats how i thought it worked :S

Its meant to be creatures.h I've change them all now (see noobie things!) Thanks for noticing but it still has the same error.

Just get rid of the paramater in the function so it looks like this void draw(); and then change the function like this

void Creatures::draw()
{
    al_convert_mask_to_alpha(sprite, al_map_rgb(255,0,255));
    al_draw_bitmap(sprite, getX(), getY(), 0);
}

This will let you use the sprite variable of the class.

Omg of course, im not sure why i was trying to pass s in when it already had sprite. It made sence when i wrote it lol. Thanks guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.