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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:04:48+00:00 2026-05-11T02:04:48+00:00

I know I’m not asking this quite right, either. Please help me better form

  • 0

I know I’m not asking this quite right, either. Please help me better form my question.

I’m having a bit of a hard time getting my mind wrapped around handles — in some ways, it looks like pointers. But unlike pointers, it seems like I can assign values directly to the handle variable, and it affects the underlying data value, not the handle itself.

The test code clearly shows that I get the same value whether I use the handle, or if I ‘dereference’ the handle to get to the data. Clearly, this wouldn’t work with unmanaged pointers. What am I not understanding?

#include <iostream>  int main() {    int ^y;   int ^a, ^b, ^c;   long x;     y= gcnew int(100);    a=y;    b=y;    c=y;     c= gcnew int(200);    b= 300;     System::Console::WriteLine(y); // returns 100 (instead of something pointer-like)    System::Console::WriteLine(*y); // also returns 100     System::Console::WriteLine(a); // 100    System::Console::WriteLine(b); // 300    System::Console::WriteLine(c); // 200      x = static_cast<long>(y);    *y = 10;     System::Console::WriteLine(x); // 10    System::Console::WriteLine(y); // 10    System::Console::WriteLine(*y); // 10    } 

Edit to add — I suspected that WirteLine might have done the dereferencing for me, but I would have expected the static cast to long would not. Is this related to autounboxing as welll?

  • 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. 2026-05-11T02:04:48+00:00Added an answer on May 11, 2026 at 2:04 am

    It’s a bit sad that C++/CLI allows this syntax. The int type is a value type, the hat is used for reference types. Your ‘y’ variable does not store an int, it stores System::Object. The compiler automatically generates a boxing instruction when you assign it. Console::WriteLine() has otherwise no problem displaying the value of an object that’s a boxed int.

    The rule of thumb: use the hat when it is a class object, omit it for simple value types. Avoid the stack semantics of a reference type (omitting the hat so it automatically calls the destructor when the scope ends) until you really grok the difference between value and reference types and why Dispose() is important.

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The simplest solution is to rewrite your main declaration thus:… May 11, 2026 at 12:14 pm
  • added an answer In the Object Explorer in Management Studio, the Connect button… May 11, 2026 at 12:14 pm
  • added an answer There's no right answer here, but most modern PHP systems… May 11, 2026 at 12:14 pm

Related Questions

I know I must be missing something, but in a while statement how does
I know I need to have (although I don't know why) a GROUP BY
I know I could write scripts and create jobs to run them, but at
I know I can do most of this by hacking Trac and using Git
I know I can programatically make the taskbar item for a particular window start
I know I can call the GetVersionEx Win32 API function to retrieve the Windows
I know I once know how to do this but... how do you run
I know I can figure out the name of the method as its being
I know I can specify one for each form, or for the root form
I know I can do this: IDateTimeFactory dtf = MockRepository.GenerateStub<IDateTimeFactory>(); dtf.Now = new DateTime();

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.