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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:41:59+00:00 2026-06-04T05:41:59+00:00

I’ve come across something in C++/CLI that goes against what I thought I knew:

  • 0

I’ve come across something in C++/CLI that goes against what I thought I knew:

Usually, if you pass an object into a function, you’d use a dot to access its methods (this also works for ref classes, with some extra constructors):

value class Value {
  void Print() { Console::WriteLine("Value"); }
};

void f(Value v) {
  v.Print();
}

Also usually, passing an object via an interface into a function forces you to put a ^ on the argument, and use -> in the method call:

interface class Base {
  void Print();
};

void f(Base ^b) {
  b->Print();
}

However, if you make f generic, with a constraint based on an interface, the compiler insists that you use ->, but also insists you don’t use ^ in the arguments list:

interface class Base {
  void Print();
};

generic <class T> where T : Base
void f(T t) {
  t->Print();
}

Up to now, I believed that referencing objects directly always uses . and referencing them through their handles always uses ->. This appears to reference an object directly using a -> – what am I getting wrong?

  • 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-04T05:42:00+00:00Added an answer on June 4, 2026 at 5:42 am

    They tried to make the C++/CLI syntax equivalent to C++ syntax but that wasn’t particularly successful. The rule is that you use . to access a member of a value type, -> to a access a member of a reference type.

    Complication number one is stack semantics. You can drop the hat to declare a local variable of a reference type. Which then automatically gets disposed at the end of the scope block, the compiler automatically generates a destructor call. An attempt to make managed types behave similar to C++ types and rescue the RAII pattern.

    Complication number two is that the compiler permits using the hat on a variable of a value type. Which is 99% of the type a mistake, particularly nasty because that’s very expensive at runtime since the value gets boxed.

    Generics made it ultimately ambiguous, the type parameter can be either a value type or a reference type. Which will make the concrete type either a value or a reference type, that isn’t sorted out until runtime. Note that this is permitted in your example, a value type may implement an interface. The rule then is that you always write the code without hats on the variables of the type parameter, treating them as through they are value types. But dereference those variables as though they were reference type references, using the arrow. Yes, very confusing.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
i got an object with contents of html markup in it, for example: string

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.