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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:37:57+00:00 2026-06-13T12:37:57+00:00

I’m trying to find out/understand exactly how you access data of an object using

  • 0

I’m trying to find out/understand exactly how you access data of an object using free functions.

So my free functions look like this (header wise anyways):

#ifndef CDSUPPORTFUN_H
#define CDSUPPORTFUN_H

void DisplayCDS(CDX *pCD1, CDX *pCD2, CDX *pCD3);
void ShowCosts(CDX &CD1, CDX &CD2, CDX &CD3);
void MemoryReturn(CDX *pCD1, CDX *pCD2,CDX *pCD3);
#endif

Then I have the implementation for what each does. My question is, exactly what do I input into my Main.cpp to access these functions? What information must I pass in the Main.cpp when I call them?

For example, when I use:

DisplayCDS(pCD1, pCD2, pCD3);

My data is displayed as intended. However is this still passing with a pointer? And how should it look if I am passing my reference?

—

EDIT: Since ShowCosts is passing by reference would the appropriate syntax to retrieve it be:

CD1.ReturnCosts();
  • 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-13T12:37:58+00:00Added an answer on June 13, 2026 at 12:37 pm

    To clear things up, there are two ways to pass by reference. You can pass pointers, which point to an instance of an object. Or you pass the actual object to the function, and have the function create references to those objects. To pass by reference with pointers (the way you have it):

    Define your function as:

    void DisplayCDS(CDX *pCD1);
    

    and in your Main, call it as:

    CDX* pCD1;
    *pCD1 = something;
    DisplayCDS(pCD1);
    

    Alternatively, if you don’t like pointers, you can define your function to take references and pass an actual object to it rather than a pointer. To do this:

    Define your function as:

    void DisplayCDS(CDX& CD1);
    

    and in your Main, call it as:

    CDX CD1;
    CD1 = something;
    DisplayCDS(CD1);
    

    These two syntaxes accomplish the same thing. You have passed a reference to your function and not copied the object. Note that there will be a difference in how you use pCD1 or CD1 in your function now. If using pointers, you’ll have to use pCD1 as:

    pCD1->CD1MemberVar = blah;
    

    or

    *pCD1.CD1MemberVar = blah;
    

    If you used the second syntax, you’ll be able to use the object in your function as normal:

    CD1.CD1MemberVar = blah;
    

    Just to further demonstrate how pointers work, you could also use this method, which is a combination of the previous two, and is unnecessarily confusing.

    Define your function as

    DisplayCDS(CDX& CD1);
    

    And in Main:

    CDX* CD1;
    *CD1 = something;
    DisplayCDS(*CD1);
    

    All of these examples should work…I prefer using the CDX& syntax to avoid the use of *’s all over the place. And ->’s.

    EDIT: As pointed out in the comments, passing a pointer is not technically “passing by reference”. It is passing an object (a pointer) that points to your object in memory.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.