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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:18:15+00:00 2026-06-07T20:18:15+00:00

So I have a class that has a protected pointer member of the following

  • 0

So I have a class that has a protected pointer member of the following type

int *assigntoThis; // In the constructor I have initialized this to NULL.

I also have a public recursive member function of the same class with the following declaration

bool find(int* parent, std::string nameofnode, int* storeParentinThis);

The recursive function checks through child nodes and if the name of the child Node matches the string passed in as a parameter it will assign the address of parent to storeParentinThis.

This is how I call the function from another function of the same class.

bool find(root, "Thread", assigntoThis);

However, during runtime when I output the value stored in assigntoThis I get 00000000 = NULL. How do I change the value of assigntoThis inside my recursive function?

  • 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-07T20:18:17+00:00Added an answer on June 7, 2026 at 8:18 pm

    change to :

    bool find(int* parent, std::string nameofnode, int*& storeParentinThis);
    

    explanation:

    here is a simplified version of your original code:

    foo (int* p) { /// p bahaves as a local variable inside foo
      p = 1;  
    }    
    int* p = 0;
    foo(p);
    // here p is still equal 0
    

    this is actually similar to following code:

    foo (int i) {
      i = 1;  
    }    
    int i = 0;
    foo(i);
    // here i is still equal 0
    

    which I think is easier to understand.

    So if we want to return something from a function we must make a pointer to it or a reference to it, going backwards with examples:

    foo (int* i) { // pointer example
      *i = 1;  
    }    
    int i = 0;
    foo(&i);
    // here i is equal to 1
    
    foo (int& i) { // using reference example
      i = 1;  
    }    
    int i = 0;
    foo(i);
    // here i is equal to 1
    

    Now it is easy to apply it to your case:

    // pointer example
    bool find(int* parent, std::string nameofnode, int** storeParentinThis) {
        *storeParentinThis = parent;
    }
    
    // reference example
    bool find(int* parent, std::string nameofnode, int*& storeParentinThis) {
         storeParentinThis = parent;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that has several member classes as attributes. The constructor of
I have a class that extends View. This class has the member variable mCanvas
I have class User that contains protected constructor and class Account that has access
i have a class that has a ConcurrentDictionary as a private member. This class
I have a class that has a vector member variable, which I fill up
i have a class say A that has a protected method say methodA(), then
I have a class that looks something like this: class Foo { protected $_arr
I have a class that defines a protected field. The protected field has a
I have a Class that has a private variable with a public setter/getter function:
I have a class that has an inner struct/class (I have decided which yet,

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.