Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:27:19+00:00 2026-06-01T16:27:19+00:00

I have several classes. class DRAW { private: unsigned int back_texture; unsigned int hero_texture;

  • 0

I have several classes.

class DRAW {
private:
    unsigned int back_texture;
    unsigned int hero_texture;

public:
    DRAW();
    ~DRAW();
    void start_draw();
    void draw_back();
    void draw_hero();
    void end_draw();

};
class HERO {

private:
    float x,y,w,h; //coordinates
    float hp; //health

public:
    friend class DRAW;

    HERO(float x1, float y1, float w1, float h1, float hp1);
    ~HERO();

    void set_posX(float x1);
    void set_posY(float y1);
    void set_height(float h1);
    void set_width(float w1);
    void set_health(float hp1);

    float get_posX();
    float get_posY();
    float get_height();
    float get_width();
    float get_health();

    void move(char direrion);

};

I have created object in the main function (hero = new HERO()) of my program. I’m trying to access the parameters of object hero from draw_hero() function.

void DRAW :: draw_hero() {

glBindTexture(GL_TEXTURE_2D, hero_texture);

glBegin(GL_QUADS);

glTexCoord2d(0,0); glVertex2f(hero->get_posX(),hero->get_posY());
glTexCoord2d(1,0); glVertex2f(hero->get_posX() + hero->get_width(),hero->get_posY());
glTexCoord2d(1,1); glVertex2f(hero->get_posX() + hero->get_width(),hero->get_posY() + hero -> get_height());
glTexCoord2d(0,1); glVertex2f(hero->get_posX(),hero->get_posY());
glEnd();

}

When I compile i het this:
draw.h:83:32: error: ‘hero’ was not declared in this scope

What is wrong with it?

ADDED: Main looks like this :

int main (int argc, char* argv[] ) {

 /* DECLARATION */

SDL_Event event;

SYSTEM* system;

bool isRunning = true;

Uint8* key;

static HERO* hero;
hero = new HERO(300,300, 40, 40, 100);

DRAW* image = new DRAW;
DRAW();
.
.
.
    /* RENDERING */


    image -> start_draw();
    image -> draw_back();
    image -> end_draw();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:27:20+00:00Added an answer on June 1, 2026 at 4:27 pm

    Declare your function with an argument something like that

    void DRAW :: draw_hero(HERO * hero) {/* rest of the code*/}
    

    and pass your pointer to created object hero to the function when calling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have classes structured like this: Public MustInherit Class A ' several properties End
Assume you have several arbitrary classes like below: class Foo { $foovar; public function
I have a base class called BaseEvent and several descendants classes: public class BaseEvent
I have a base class where I derive several classes. I have another class
I have a base class Media and several derived classes, namely DVD , Book
I have a file attachment class (FileAttachment) which is used in several other classes.
Let's say I have a Base class and several Derived classes. Is there any
I have several classes that are basically interfaces to database rows. Since the class
I have an abstract class: class A { public: bool loaded_; virtual int load()
I have several classes from 3rd party library similar to the class, StagingConfigDatabase, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.