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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:21:32+00:00 2026-06-11T03:21:32+00:00

I am passing object as pointer and then I want to use passed objects

  • 0

I am passing object as pointer and then I want to use passed objects values to assign them to other method.

This is how I pass object:

Author *pAuthor = new Author("John", "Doe");
Publisher *pPublisher = new Publisher("Wrox", "10475 Crosspoint Blvd.", "Indianapolis");
Book *pBook = new Book("Memory Management", pAuthor, pPublisher, 39.99);

cout << pBook->getBookInfo() << endl;

Now, In other class I must read those passed variables from object and assign them somewhere else. In this code I am using only passed values and no object because I’m not sure how to deal with them.

Book::Book(string title, Author *pAuthor, Publisher *pPublisher, double price)
{
    this->title = title;
    this->price = price;
}

How do I read passed values from passed object?

Edit, There might be some confusion in my question. The below code must access the variables and insert then into methods which will later use them.

Each variable I try to insert look like this. I don’t want to access the author’s private variables because no way I can acces when they are set private, and yet they are still empty.

The code I have right now is:

Book::Book(string title, Author *pAuthor, Publisher *pPublisher, double price)
{
    this->title = title;
    this->price = price;

    author.setFirstName();
    author.setLastName();

    publisher.setName();
    publisher.setAddress();
    publisher.setCity();
}
  • 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-11T03:21:33+00:00Added an answer on June 11, 2026 at 3:21 am

    Use this syntax, supposing you have these variables and they are public.

    pAuthor->first_name ;
    pAuthor->last_name ;
    

    And for other class.

    pPublisher->author ;
    pPublisher->name ;
    pPublisher->place ;
    

    The '->' operator dereferences pointer to the object, or in other words, takes you to your desired variables.

    It is better if you use these data members as private members. If you do so, you cannot access them directly. You would have to use getter and setter functions to read and write their values.

    They would look like this.

    pAuthor->getfirst_name() ;
    pAuthor->getlast_name() ;
    
    pPublisher->getauthor() ;
    pPublisher->getname() ;
    pPublisher->getplace() ;
    

    Lastly it is better if you dont pass by value these object. Pass them by reference and use const before them.

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

Sidebar

Related Questions

I'm trying to pass an ivar pointer to a method and then place a
I am passing an object like this: -@users.each do |user| %tr %td=link_to(user.first_name, users_user_path(user), :title
I'm passing an object from activity to another. Then from that activity to another
Passing an object by reference is an easier, faster and safer way to pass
If one passes an object to a method using the 'Ref' keyword then what
I'm working with third-party COM object that has some of its methods passing values
Here is the problem: I am passing a pointer to an object to performSelector:withObject
I'm trying to pass pointer to pointer to a method, but apparently ARC has
I have a vector of pointers to Mouse objects called 'mice'. I'm passing the
Possible Duplicate: passing in object by ref With the code below, the output would

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.