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

  • Home
  • SEARCH
  • 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 7650571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:17:06+00:00 2026-05-31T11:17:06+00:00

I need one clarification in c++ linux. I have class C1 and another class

  • 0

I need one clarification in c++ linux.

I have class C1 and another class C2. C1 will have the reference of C2.

class C1
{

   C2 &obj ;

}

i am thinking of two choices here ,

  1. Directly holding the reference of C2 as C2 &obj;
  2. Creating the pointer of C2, as c2* obj;

Which is good ? what is the difference in it ? when choose either?

  • 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-05-31T11:17:07+00:00Added an answer on May 31, 2026 at 11:17 am

    Avoid using a reference member as much as possible.

    The same differences as that of references and pointers apply here,
    If you have a reference member then it must be initialized at the time of creation of your class object you cannot have a lazy initialization as in case of pointer member because references cannot be NULL and cannot be reseated, while a pointer member can be made to point to a C2 instance lazily as and when required.

    Also, note that there are other side effects as well, Once you have a reference member the compiler will not generate the copy assignment operator(=) & You will have to provide one yourself, It is cubersome to determine what action your = operator shall take in such a case.

    For most practical purposes(unless you are really concerned of high memory usage due to C2 size) just holding an instance of C2 as member of C1 should suffice, instead of pointer or reference member, that saves you a whole lot of worrying about other problems which reference/pointer members bring along though at expense of extra memory usage.

    If you must, use a pointer make sure you use a smart pointer instead of a raw pointer, that would make your life much easier with pointers.

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

Sidebar

Related Questions

I have one clarification, class Foo { } main() { Foo obj; //1 method(obj);
I have a Flex button. I need one color on the left and another
Someone have any sample of Comet app .net? I need one sample how to
When or why will one need to use Globally Unique Identifiers instead of the
I need a clarification on one of scenarios of <xsd:any> . What if namespace
I need to find the number of days between two dates : one is
I need some clarification how MS-DTC will behave in scenario given below 1) I
I need clarification regarding an issue related to multithreading. I have threads which acquires
I need some clarification. Are these two methods the same or different? I get
Hopefully this will be an easy one to answer. I created a class in

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.