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 7726141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:08:25+00:00 2026-06-01T05:08:25+00:00

So I have this problem where the output prints the address of my pointer,

  • 0

So I have this problem where the output prints the address of my pointer, I have no idea why this happens cuz the pointers is not modified at all

Heres the code:

using namespace std;

class AndroideAbstracto {
protected:
    int *vida;
    int *fuerza;
    int *velocidad;
public:

    void setvalores(int vi, int fu, int ve) {
        velocidad = &ve;
        vida = &vi;
        fuerza = &fu;

    };
    virtual void imprimir(void) = 0;
};

class Androide : public AndroideAbstracto {
public:

    void imprimir() {
        std::cout << "Caracteristicas del androide:" << endl;
        cout << "Velocidad = " << *velocidad << endl;
        cout << "Vida = " << *vida << endl;
        cout << "Fuerza = " << *fuerza << endl;

    };

};

class Decorator : public AndroideAbstracto {
protected:
    AndroideAbstracto *AndroideDec;
public:

    Decorator(AndroideAbstracto* android_abs) {
        AndroideDec = android_abs;
    }
    virtual void imprimir(void) = 0;
};

class Androide_Con_Habi : public Decorator {
protected:
    string habilidad;
public:

    Androide_Con_Habi(AndroideAbstracto* android_abs, string habi) : Decorator(android_abs) {
        habilidad = habi;
    }

    virtual void imprimir() {
        AndroideDec->imprimir();
        cout << "La habilidad especial del androide es: " << habilidad << endl;
    }
};

class Androide_Elegido : public Decorator {
protected:
    bool elegido;
public:

    Androide_Elegido(AndroideAbstracto *android_abs, bool es) : Decorator(android_abs) {
        elegido = es;
    }

    virtual void imprimir() {
        if (elegido) {
            //            *vida =(*vida) * 2;  //Im quite new to C++ so im not really
            //            *fuerza *=2;         //sure how should I multiply these pointers
            //            *velocidad *=2;
            //            AndroideDec->setvalores(vida*2,fuerza*2,velocidad*2);
            AndroideDec->imprimir();
            cout << "Este androide es uno de los elegidos";
        }
    }
};

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

    Androide *andro = new Androide();
    andro->setvalores(600, 700, 300);
    andro->imprimir();
    Androide_Con_Habi *andro_con_habi = new Androide_Con_Habi(andro, "Volar");
    andro_con_habi->imprimir();

    Androide_Elegido *superpoderoso = new Androide_Elegido(andro, true);
    superpoderoso->imprimir();

    delete superpoderoso;
    delete andro;
    delete andro_con_habi;
    return 0;
}

I have no idea why but this prints:

Caracteristicas del androide:
Velocidad = 300
Vida = 600
Fuerza = 700

Caracteristicas del androide:
Velocidad = 300
Vida = 152436744
Fuerza = -1074718788
La habilidad especial del androide es: Volar


Caracteristicas del androide:
Velocidad = 300
Vida = 152436744
Fuerza = 1
Este androide es uno de los elegidos 
  • 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-01T05:08:27+00:00Added an answer on June 1, 2026 at 5:08 am
    void setvalores(int vi, int fu, int ve) {
        velocidad = &ve;
        vida = &vi;
        fuerza = &fu;
    
    };
    

    The pointers to vi, fu, and ve get invalidated when the function returns. You’re not seeing addresses being printed, but simply garbage.

    Your entire design doesn’t and shouldn’t need to use pointers though.

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

Sidebar

Related Questions

i have this problem: ms-access could not delete and i found a potential solution
I have this problem, in a form I have a list of customers that
I have this problem where I open Visual Studio and the internal windows are
i have this problem to find a particular xml node l have post this
I have this problem I've been trying to tackle for a while. I have
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem that my sites uses alot of ajax and when a
I have this problem containing some inequations and requirement to minimize a value. After
I have this problem decomposing a relation schema into a set of schemas that
I am a Python newbie. I have this small problem. I want to print

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.