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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:29:06+00:00 2026-06-15T12:29:06+00:00

Sample code: MyItemType a; MyItemType b; a.someNumber = 5; b = a; cout <<

  • 0

Sample code:

MyItemType a;
MyItemType b;
a.someNumber = 5;
b = a;

cout << a.someNumber << endl;
cout << b.someNumber << endl;

b.someNumber = 10;

cout << a.someNumber << endl;
cout << b.someNumber << endl;

The output:

5
5
5
10

If a and b were reference types, the last 2 lines would have been 10 and 10 instead of 5 and 10 I guess.

Does this mean when you do a declaration like this:

AClassType anInstance;

it is treated like a value type?

——Here is MyItemType.h————

#ifndef MYITEMTYPE_H
#define MYITEMTYPE_H

class MyItemType{

public:
    int someNumber;
    MyItemType();
};

MyItemType::MyItemType(){
}

#endif  /* MYITEMTYPE_H */
  • 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-15T12:29:07+00:00Added an answer on June 15, 2026 at 12:29 pm

    It is not treated like a value type, in fact it is.

    While in Java object variables store references to objects, in C++ there is an important difference between an object and its reference. Assignment is by default really by value.

    If you want a variable to be just a reference, you use either a reference or a pointer type, depending what you want to with it. These types are declared T* and T&.

    To illustrate this a little more:

    In Java, when you say MyClass obj, an object is created, but a reference/pointer is stored in the variable obj.

    In C++, MyClass obj creates the object and will stored it in obj. If you want to work with references/pointers, you need to declare variables explicity as MyClass* objPointer or MyClass& objReference.

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

Sidebar

Related Questions

In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}
I have the following sample code and noticed that if I attempt to use
Sample code is at the end of the post for reference. Sorry for being
Sample code / workflow would be helpful.
I have a sample code: $text = abc ABC def ghi Abc aBc xyz;
Any sample code that would show me how to, in my iPhone application code:
Sample code: <div id='container'> <h1>heading 1</h1> <h2>heading 2</h2> <p>paragraph</p> </div> I would like a
I have downloaded the sample code for TouchImageView and set the minScale to .80
The sample code uses JQuery to prevent the user from unchecking the last checked
Sample Code: var Day = Ember.Object.extend({ date:null, activities:null, // is set to an Em.ArrayProxy

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.