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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:30:07+00:00 2026-06-17T01:30:07+00:00

I’m trying to get two different classes to interact with eachother, for that I

  • 0

I’m trying to get two different classes to interact with eachother, for that I have in one class a pointer to an object of an other class, which is specified in the constructor.
Interaction works so far, I can change the paramters of the pointed-to object and I can see the changes, as I’m printing it on a terminal. BUT when I try to get a parameter from this object and try to print it to the terminal through the class which points to it I only get a zero value for an Int from which I know, cause of debug outputs, that it isn’t zero, if called directly.
I will give you an example of the code:

Class A:

class Spieler
{
    private:
        int score;
        Schlaeger *schlaeger;
        int adc_wert;
        int channel;


    public:

        Spieler(int x, Schlaeger &schl, int adc_wert_c=0, int channel_c=0 )
        {
            score=x;
            schlaeger=&schl;
            adc_wert=adc_wert_c;
            channel=channel_c;
        }
    //....
        void set_schl(Schlaeger &schl){ schlaeger=&schl;}
        int getPosY(){ schlaeger->getSchlaeger_pos_y();}
        int getPosX(){ schlaeger->getSchlaeger_pos_x();}
        void setPosY(int y){ schlaeger->set_pos_y(y);}      

        void schlaeger_zeichen(){
            schlaeger->schlaeger_zeichen();
        }

        void schlaeger_bewegen(){
            schlaeger->schlaeger_bewegen(getADC());
        }
//...

};

Class B:

class Schlaeger
{
    private:
        int schlaeger_pos_x;
        int schlaeger_hoehe;
        int schlaeger_pos_y;
    public:

        Schlaeger(int x=0, int h=5, int pos_y=15)
        {
            schlaeger_pos_x=x;
            schlaeger_hoehe=h;
            schlaeger_pos_y=pos_y;
        }

        int getSchlaeger_pos_x()
        {
            return schlaeger_pos_x;
        }
        int getSchlaeger_pos_y()
        {
            return schlaeger_pos_y;
        }
        int getSchlaeger_hoehe()
        {
            return schlaeger_hoehe;
        }
        void set_pos_y(int new_y)
        {
            schlaeger_pos_y=new_y;
        }


};

The calls to the changing methods work, I can see the changes and I can see it in a debug output.

  • 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-17T01:30:09+00:00Added an answer on June 17, 2026 at 1:30 am

    You’re not returning the value in the getter

    int getPosY(){ schlaeger->getSchlaeger_pos_y();}
    

    should be

    int getPosY(){ return schlaeger->getSchlaeger_pos_y();}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.