<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Stan Lippman's BLog</title><subtitle type="html">C++/CLI</subtitle><id>http://blogs.msdn.com/slippman/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/slippman/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2004-06-02T14:56:00Z</updated><entry><title>The String Literal Returns</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/12/08/278163.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/12/08/278163.aspx</id><published>2004-12-08T05:26:00Z</published><updated>2004-12-08T05:26:00Z</updated><content type="html">&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;In the last entry, I celebrated what I felt was an elegant solution to the problem of the string literal in the context of overload function resolution. But it turns out there is another area in which the string literal proves problematic. Who would have thought such a foobar kind of entity could cause so much trouble? It's these kinds of ambushes that makes the extension of a language so unpredictable. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;So, here's the problem.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;throw "fritz";&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;what does the compiler do? it has to set everything up at compile-time, then it actually gets handled by a run-time library that makes use of a limited form of type reflection to figure the kind of object having been thrown. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;there's no context, really. we don't know if the person is going to catch x, y, or z, so we can't know what to throw in any particular instance. this is all set up at compile-time. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Now, here is the rub:&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void f()&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;try { g(); }&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;catch ( String^ s ) {}&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;catch ( const char* pcs ) {}&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void g()&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;throw "fritz";&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;What gets caught? what an impossible question. one could argue if we are compiling for the CLR, then String^ should match, and if we are in native, and so on. But there's no reason to believe that just because we are compiling for the CLR, people are using String and not just const char*. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;So, a string literal is thrown as a type const char*, not as String^. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;My first reaction was, gosh, that's terrible. Then, I thought, what am I thinking? It seems a very small matter. It's not even something I would run into since I don't throw anything but class objects. I just add it for completeness. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;I think if this bothers you, then you are bothered by our entire effort. Just as a sounding. That is, not everybody is happy with our work on C++/CLI. There are some folks out there that feel concern that we are somehow messing with their language, and we shouldn't be allowed to do that.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;we aren't doing it that way at all. We have really wanted to be good c++ citizens while being excellent Microsoft employees. I have never felt any pressure to compromise either while I have been here. We have had an extraordinary degree of freedom not simply in our design, but in our being able to reach out and work with the general c++ community. this language is a coalition. I think we have all wanted to put the best face on C++ in what we regard as an otherwise hostile environment for C++. We think this is a win-win situation for everyone. if you don't like something, you should let us know. we're not a hundred thousand leagues removed from our users. if you want to use the language, you have every right to tell us what you think about it; how you find it; what you want. if you make a good case for it, I think it could be done. that's just my opinion. but I think we have an opportunity to together as a C++ community put forth C++ in an otherwise hostile environment that for some unbelievable reason thinks C# or Java comes anywhere near being as good a language. I don't understand it. It's not a question of knocking those languages. They took so much from C++ -- it's not hard, after all the hard stuff was worked out, to go back and clean it up. sure. C++ is messy. it was real hard to do. it was getting done while we were using it. we didn't know where it was going. Bjarne was implementing it, using it, it became the tool we all used to make our living. we wanted it to be the best possible language for programmers. at least I did. I don't have a philosophy. I don't make standards. I just program and write. and I do that best in C++. C# and Java mean nothing to me. Now I have my own language to use on .NET. That was my personal agenda in all this. I think you should check it out. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;it was a great adventure. I find C++/CLI is something interesting again about C++ for me anyway. I'm not a fan of standards. I've never finally been involved in one. It's making a language that interests me, not in clean-up and all that necessary stuff for real-world production. I don't have the head for that.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;so, I just wanted to make a personal statement. I have watched the team here for almost 3 years. I worked with them sometimes. I snarled at them sometimes. I was fed up with them once or twice. and yet they have produced something really wonderful in my opinion, and it is much better than I had dared imagine. I just love it. I can't wait to program with it – I'd like to drop everything and just start. this is exactly what I have been waiting for. to have a language to program .net. we didn't have one before. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;C++/CLI is a entry visa nto what I call 3-dimensional programming. The CLR gives you the run-time as an entity to query, to modify, to almost in a sense be alive in. everything in a native program has to be done at compile-time. that is way too early for me to know exactly what needs to be done in many interesting environments. can't I wait? I'm not that performance critical that I need the machine. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;my first analogy was going to be between the traditional Disney animation and the Pixar CGI, but I think a better analogy is between an instinct and a decision. that is, an instinct is the trigger of a built-in behavior that is insulated from and unaffected by the environment. a decision considers the environment (context) and memory (past behavior) in order to choose a best action. this is what is missing from native static programming. it really can't be smart enough for the kinds of problems we need to solve now in my estimate. I can't prove that. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;I gave a talk at Disney Feature Animation a few months ago about C++/CLI, and a friend of mine who I love dearly, asked me, what do I need that for? he is in charge of plug-in 3D tools for Maya, a modeling toolkit for computer graphics. And he is right. But we need it I believe as a community going forward. and in that sense, we have opened that doorway for the C++ programmer. The worst case scenario was that the price of admission to this world was to have to renounce C++ -- I mean, mea culpa. we're such savages – we worry about performance, we break the type system, we make use of the underlying machine, we don't follow enough rules. we're loose cannons. Can't have loose cannons. I personally didn't want to accept that as being a true statement.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;But you cannot argue something like that. I can't say, hypothetically, C++ can be as good a language under .NET as Java or C#. Nobody would hear that – they would just see Lippman being defensive, or delusional. you have to demonstrate it. That's the only way to really convince people. That's the only way I can ever convince myself in fact. So, that is what C++/CLI means to me.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;I know Bjarne has his reservations and dislikes. Well, so do we all, if truth be told. But it's still just so wonderful overall. who cares if it's not perfect. I don't – I haven't gotten anything perfect, trust me. i don't know if it is better than this or that or the next thing. but it's really pretty good and i'm going to use it. and we really did it as a team.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=278163" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>The Type of a String Literal Revisited ...</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/12/04/275069.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/12/04/275069.aspx</id><published>2004-12-04T14:14:00Z</published><updated>2004-12-04T14:14:00Z</updated><content type="html">&lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;In the course of these entries, I have twice addressed the issue of the type of a string literal under C++/CLI -- in particular when resolving an overloaded function call. The issue is illustrated in the following example,&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;public ref class R {&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;public:&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; void foo( System::String^ ); // (1)&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;void foo( std::string );&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// (2)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; void foo( const char* );&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// (3)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;};&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;{&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; // which one?&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; r-&amp;gt;foo( "Pooh" );&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;In the original Managed Extensions for C++, the invocation of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;foo()&lt;/span&gt; within &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;bar()&lt;/span&gt; resolved to (3), exactly the same as it does under ISO-C++. That is,&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; // under Managed Extensions to C++, resolved to&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;// void foo( const char* );&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; r-&amp;gt;foo( "Pooh" );&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;}&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;To briefly review: In ISO-C++, the type of "Pooh" is &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt;&lt;span style="FONT-SIZE: 11pt"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char[5]&lt;/span&gt;. There is no &lt;i&gt;exact&lt;/i&gt; match of "Pooh" to any of the three instances of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;foo()&lt;/span&gt;. However, the &lt;i&gt;trivial&lt;/i&gt; &lt;i&gt;conversion&lt;/i&gt; of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt;&lt;span style="FONT-SIZE: 11pt"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char[5]&lt;/span&gt; to &lt;span style="FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;span style="FONT-FAMILY: 'Courier New'"&gt;char*&lt;/span&gt; represents a best match, and this is why (3) is invoked. There was no built-in notion of a string literal having any relationship to &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt;. &lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;And this was changed in the design of C++/CLI. Actually, it was changed twice, and that is the talking point of this entry – to explain why the initial change had to be further refined. &lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;The overall effect of the change is to extend dual citizenship to a string literal compiled for the CLI. The initial change is described in my earlier entry entitled &lt;i&gt;String Literals are now a Trivial Conversion to String&lt;/i&gt;. Here is a brief review of the issue.&lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;The first question is, what is the exact type of "Pooh" within C++/CLI? One answer is, &lt;i&gt;well, obviously, it is of type &lt;/i&gt;&lt;i&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;/i&gt;&lt;i&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;char[5]&lt;/span&gt; – otherwise, it could not be compatible with ISO-C++&lt;/i&gt;. We can't change that.&lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;The initial solution, therefore, was to introduce a new trivial conversion, that of a string literal to a &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt;, that is of equal precedence with the trivial conversion of a string literal to &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/span&gt;. This provides a somewhat elegant symmetry, but in practice results in a flurry of ambiguous calls. For example, under this design, the invocation of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;foo()&lt;/span&gt; now fails,&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; // under interim C++/CLI, flagged as ambiguous&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;// the following two candidate functions are equally good …&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;//&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void foo( System::String^ );&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;// &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;void foo( const char* );&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; r-&amp;gt;foo( "Pooh" );&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;}&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;To disambiguate the call, the user would have to provide an explicit cast,&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;{&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; // ok: void foo( System::String^ );&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; r-&amp;gt;foo( safe_cast&amp;lt;String^&amp;gt;( "Pooh" ));&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;In practice, in nearly every case, the C++/CLI programmer wished to have the &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;String&lt;/span&gt; instance invoked in preference to the C-style string instance. And so giving equal precedence to both conversions was both a step forward (in recognizing the special relationship of a string literal to &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt; under the CLI) and two steps back (the presence of the &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/span&gt; argument in effect neutralized that relationship (first step back) and required an explicit cast to resolve (second step back) ).&lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;So, we had to fix that. That is, under the CLI, we want a string literal to more closely be a kind of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt; than &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/span&gt;. The question was, how could that be achieved without breaking ISO-C++ compatibility? How might you resolve that?&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;font face="Tahoma"&gt;The insight to resolve this is to realize that the dual citizenship of a string literal applies to its fundamental type, not to its set of trivial conversions. &lt;span style="mso-bidi-font-size: 12.0pt"&gt;In effect, under C++/CLI, the underlying type of a string literal such as "Pooh" is &lt;i&gt;both&lt;/i&gt; &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt; &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char[5]&lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt; (its native inheritance) and &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt; &lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;(its managed underlying unified type). Under C++/CLI, the string literal is an exact match to &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt; and the trivial conversion to &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;const&lt;/span&gt; &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt; is not considered. That is, under the revised C++/CLI language specification, the ambiguity has been resolved in favor of &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;System::String&lt;/span&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&amp;nbsp; // ok: under current C++/CLI, &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;//&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void foo( System::String^ );&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="3"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; r-&amp;gt;foo( "Pooh" );&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="3"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;font face="Tahoma"&gt;This reflects a fundamental difference between &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;ISO-C++&lt;/span&gt;&lt;/i&gt; and &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;C++/CLI&lt;/span&gt;&lt;/i&gt; in their type systems. In &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;ISO-C++&lt;/span&gt;&lt;/i&gt;, types are independent except when explicitly part of the same class inheritance hierarchy. Thus, there is no implicit type relationship between a string literal and the &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'"&gt;std::string&lt;/span&gt; class type, even though they share a common abstraction domain. &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;font face="Tahoma"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;C++/CLI&lt;/span&gt;&lt;/i&gt;, on the other hand, supports a &lt;i style="mso-bidi-font-style: normal"&gt;unified&lt;/i&gt; type system. Every type, including literal values, is implicitly a kind of &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'"&gt;Object&lt;/span&gt;. This is why we can call methods through a literal value or an object of the built-in types. The value &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'"&gt;5&lt;/span&gt; is of type &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'"&gt;Int32&lt;/span&gt;. The string literal is of type &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Courier New'"&gt;String&lt;/span&gt;&lt;span style="mso-bidi-font-family: 'Courier New'; mso-bidi-font-size: 12.0pt"&gt;. It just doesn't work to treat a string literal as either more like or equal to a C-Style string.&lt;/span&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;font face="Tahoma"&gt;The integrated conversion hierarchy allows a working ISO-C++ program to continue to exhibit the same behavior when compiled for the CLI, while a new C++/CLI program exercising the CLI types reflects the new type priority of the string literal. &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;span style="mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Tahoma"&gt;Most readers and programmers have little patience with this level of detail, and often point to discussions of C++ type conversions as evidence of its complexity. However, I don't think that is quite fair. The existence of these rules is necessary if one is to reach an intuitive language behavior and guarantee a uniform behavior across implementations. It is because the language generally behaves in a type-intuitive way that allows programmers in fact to ignore these details.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in; TEXT-INDENT: 0in"&gt;&lt;font face="Tahoma"&gt;While the length of this discussion might seem disproportionate to the topic's importance, it strikes me as a canonical example of the extent to which we have had to work to integrate the CLI type system into the ISO-C++ semantic framework. This should also suggests certain good practices when a native class is being recast to a CLI class type. It is better, for example, to refashion the set of member functions accepting string literals rather than simply stirring in an additional &lt;span style="FONT-FAMILY: 'Courier New'"&gt;String&lt;/span&gt; instance to our stew of overloaded functions, seasoning it to local taste.&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=275069" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>A Primer on the Interior Pointer </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/27/221373.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/27/221373.aspx</id><published>2004-08-27T05:07:00Z</published><updated>2004-08-27T05:07:00Z</updated><content type="html">&lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;A value type is typically not subject to garbage collection except in two cases: (a) when it is the subject of a box operation, either explicit or implicit, such as,&lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;void f( int ix ) &lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// explicit placement on the CLI heap&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int^ result = gcnew int( -1 );&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// exercise result …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// implicit boxing of the integer value ix …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console::WriteLine( "{0} :: {1}", ix, result );&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;and (b) when it is contained within a reference type either as a member or as an element of a &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; array. For example,&lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public enum class Color &lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{ white, red, orange, yellow, green, blue, indigo, violet };&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public value class Point &lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Color m_color;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;float m_x, m_y;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public ref class Rectangle &lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Point bottom_left;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Point top_right;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;void f( Point p )&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Rectangle&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;^hit = gcnew Rectangle( -2, -2, 2, 2 ); &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;array&amp;lt;int&amp;gt; ^fib = gcnew int(8){ 1,1,2,3,5,8,13,21 };&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;} &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;In &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;f()&lt;/span&gt;, we allocate two &lt;i style="mso-bidi-font-style: normal"&gt;whole&lt;/i&gt; objects on the &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; heap, a &lt;font size="3"&gt;&lt;font face="Tahoma"&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Rectangle&lt;/span&gt; and an array of eight integer elements. The &lt;/font&gt;&lt;font face="Tahoma"&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Rectangle&lt;/span&gt;&lt;/font&gt;&lt;/font&gt; object contains two interior value class &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Point&lt;/span&gt; members. These are located on the &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; heap as fixed offsets into the area allocated to the containing &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Rectangle&lt;/span&gt;. Within each &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Point&lt;/span&gt; are two floating point members and a &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Color&lt;/span&gt; member. These are also located on the &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; heap as fixed offsets into the two interior &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Point&lt;/span&gt; objects. &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;If the &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Rectangle&lt;/span&gt; object is relocated during a sweep of the garbage collector, all its interior members, of course, are relocated as well. The same is true with a &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; array. When the array is relocated, the addresses of each of its elements change as well. We cannot safely assign the address of any interior member or array element to a non-tracking pointer or reference. This isn't just a pitfall that we must learn to recognize and sidestep. Rather, the language disallows it. Our attempt results in a compile-time error. For example,&lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;// error: cannot assign an interior member &lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;//&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;to a non-tracking pointer …&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;Point *p_bl = hit-&amp;gt;BottomLeft;&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;We need a form of tracking entity to hold the address of an interior member. What are some of the requirements on this entity? Well, one common pattern we felt necessary to support is that of an iterator – in particular when applied to the elements of a &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;CLI&lt;/span&gt;&lt;/i&gt; array. For example,&lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;void f( array&amp;lt;int&amp;gt; ^fib )&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i style="mso-bidi-font-style: normal"&gt;SomeTrackingPointerNotation&lt;/i&gt; begin = &amp;amp;fib[0];&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;i style="mso-bidi-font-style: normal"&gt;SomeTrackingPointerNotation&lt;/i&gt; end = &amp;amp;fib[ fib-&amp;gt;Length ];&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for ( ; begin != end; ++begin )&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;} &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;Our &lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt"&gt;SomeTrackingPointerNotation&lt;/span&gt;&lt;/i&gt; needs to support pointer arithmetic. That is, when we write &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;++begin&lt;/span&gt;, this does not increment the address by 1, but rather by the size of the element type. For example, since array element are of type &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/span&gt;, each increment must add &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;sizeof(int)&lt;/span&gt; to the current address value. &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;Neither the tracking handle (&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;^&lt;/span&gt;) nor its indirect cousin, the tracking reference (&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;%&lt;/span&gt;), supports pointer arithmetic. Moreover, a tracking reference does not support pointer comparison, such as &lt;/font&gt;&lt;/p&gt; &lt;p class="codeoneline" style="MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;begin != end &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;Like a native reference, a tracking reference, once initialized, serves as an alias to the underlying object to which it refers. The comparison is not of the two tracking addresses but of the values stored at those addresses. This is not the iterator semantics we need.&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;In a native design, we decide whether to go with a pointer or a reference declaration based on two primary factors: &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in 6pt 61.35pt; TEXT-INDENT: -39.75pt; tab-stops: list 61.35pt; mso-list: l0 level1 lfo1"&gt;&lt;span style="mso-fareast-font-family: Palatino; mso-bidi-font-family: Palatino"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face="Palatino"&gt;(1)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face="Tahoma"&gt;if the object we wish to refer to is unavailable at the time of declaration, then we must declare a pointer and set it to null. A reference requires an initial object.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;So does a tracking reference.&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in 6pt 61.35pt; TEXT-INDENT: -39.75pt; tab-stops: list 61.35pt; mso-list: l0 level1 lfo1"&gt;&lt;font face="Tahoma"&gt;&lt;span style="mso-fareast-font-family: Palatino; mso-bidi-font-family: Palatino"&gt;&lt;span style="mso-list: Ignore"&gt;(2)&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;if we wish to refer to more than a single object during the lifetime of the declaration, then we must also declare a pointer. A reference cannot be reset to refer to a second or subsequent object. Neither can a tracking reference. &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;What this suggests is that we need an analogous choice when the constraints of a tracking reference make it ill-suited to our design. A third, more flexible form of tracking entity, the interior pointer (&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;interior_ptr&amp;lt;&amp;gt;)&lt;/span&gt;, is given over to this role. It can refer to no object (but only by setting it to nullptr, not &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;0&lt;/span&gt;). And it can be reset to refer to a second or subsequent object. Moreover, it supports both pointer arithmetic and pointer comparison. For example,&lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;int sum( array&amp;lt;int&amp;gt; ^arr )&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;{&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if ( ! arr )&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return 0;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;interior_ptr&amp;lt;int&amp;gt; begin = nullptr;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;interior_ptr&amp;lt;int&amp;gt; end = &amp;amp;arr[ fib-&amp;gt;Length ];&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int sum = arr[0];&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for ( begin = &amp;amp;arr[1]; begin != end; ++begin )&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum += *begin;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return sum;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;} &lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;font face="Tahoma"&gt;The declaration of an interior pointer is limited to local objects, including function parameters and return types. If we don't provide an initial value, the compiler automatically inserts code to set it to &lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;nullptr&lt;/span&gt; – so the explicit initialization in the above example is not strictly necessary. The type specified within the template brackets identifies the kind of object addressed; we do not indicate a pointer within the brackets unless we intend two or more levels of indirection. For example, &lt;/font&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public ref class Matrix sealed {&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;float *m_mat;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public:&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;property interior_ptr&amp;lt;float*&amp;gt; Mat&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{ &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;interior_ptr&amp;lt;float*&amp;gt; get(){ return &amp;amp;mp_mat; } &lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=221373" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Translation Guide between Managed Extensions and the new C++/CLI binding Available</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/21/218487.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/21/218487.aspx</id><published>2004-08-22T02:27:00Z</published><updated>2004-08-22T02:27:00Z</updated><content type="html">&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;C and C++ programmers are notorious for relying on pointer indirection, and it seems blog entries are not immune to this. A translation guide attempting to exhaustively detail the differences between the original Managed Extensions for C++ (released with Visual Studio.NET) and the revised C++ binding to the CLI scheduled for Visual Studio 2005 &lt;span style="mso-spacerun: yes"&gt;(&lt;/span&gt;and attempting to provide some motivation behind each change) has been posted on MSDN at the following URL: &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;a href="http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp"&gt;http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp&lt;/a&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"&gt;&lt;a href="https://mail.microsoft.com/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/visualc/default.aspx?pull=/library/en-us/dnvs05/html/TransGuide.asp" target="_blank"&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Although there has been considerable effort made in correcting all errors within the text, I am sadly aware that how imperfect these pieces of mine nevertheless turn out. So, on the one hand, I believe this guide will prove valuable to those needing this information. On the other hand, I also believe there are areas that (a) could have been made clearer, and (b) details that … well, that are in error. If you do use this guide and find either (a) or (b) (or some (c), (d), or (e) not itemized), please let me know, either by a comment to this entry or by a private email. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;Speaking of which – comments, that is. Due to the open nature of the internet, the providers of this site have found it necessary to provide a form of budget firewall – that is, they have put in place a facility to &lt;i style="mso-bidi-font-style: normal"&gt;moderate&lt;/i&gt; the comments. This basically means that I see each comment before it becomes public, and it requires a click of my mouse in order for it to be published. I have not – not as yet, anyway – not published a comment; however, oddly enough, I can't prove that. &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;In any case, those of you whom have been reading this from the beginning will notice that patchwork pieces of the translation guide have been posted here in one form or another. Often, comments have helped me recognize shortcomings and recast material in a hopefully more comprehensible manner. For example, my treatment of deterministic finalization in the translation guide was considerably reworked to address some of the posted comments to the initial blog entry on that topic. As W.H.Auden said in a different context, a piece of writing is never finished, it is simply abandoned. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=218487" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>An Tour of the STL.NET</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/14/214536.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/14/214536.aspx</id><published>2004-08-14T04:42:00Z</published><updated>2004-08-14T04:42:00Z</updated><content type="html">&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;Part of the (reasonably pleasant) distractions from posting on this blog recently has been working up the first in a series of articles on STL.NET for our Visual C++ MSDN web site. The amount of work to get from an articulation of a topic to a formal publication of it is an amazingly labor-intensive 10% -- similar to the difference between prototyping a software solution and making it deployment ready. In any case, this relatively content-free entry is just to alert you of its going on-line at &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"&gt;&lt;u&gt;&lt;span style="mso-field-code: ' HYPERLINK '''"&gt;&lt;span class="MsoHyperlink"&gt;http://msdn.microsoft.com/visualc/?pull=/library/en-us/dnvs05/html/stl-netprimer.asp?frame=true&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;If for some reason, this doesn't show up in the post as a clickable link, you can just visit the visual c++ subportion of the msdn site at&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/visualc"&gt;http://msdn.microsoft.com/visualc&lt;/a&gt; &lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;and hopefully find a link to it there. In any case,&amp;nbsp;the Visual C++ site, under the care and breeding of Brian Johnson and Ami Vora,&amp;nbsp;has really been spiffed up with some very neat content and is worth a lookie-loo. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;For the article, David Clark, who did a wonderful job editing the piece, asked me to come up with a summary limited to 200. I misread that as 200 words, and wrote the following. I then discovered to my chagrin that it referred to 200 characters, including white space. I thought, well, white space is without content, so if I remove that, I get perhaps another 75 characters to play with, but that doesn't actually work … In any case, here is the summary that had to be sliced mercilessly:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;For the experienced programmer, the hardest part of moving to a new development platform such as .NET is often the absence of familiar tools through which she has honed her skills and on which she depends. For the experienced C++ programmer, one such essential toolkit is the Standard Template Library (STL), and its absence under .NET until now has been a significant disappointment. With Visual C++ 2005, we fix that by providing an STL.NET library. This article, the first in a series, provides a general overview of the STL program model using STL.NET – it discusses sequential and associative containers, the generic algorithms, and the iterator abstraction that binds the two, using plenty of program examples to illustrate each point. It begins by briefly considering the alterative container models available to the .NET programmer using C++ -- the existing System::Collections library, the new System::Collections::Generic library, and, of course, STL.NET. To provide for the widest readership, this article does not require familiarity with the STL library; however, it does presume some experience with the C++ programming language.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;This summary, when reduced to 200 characters, plus the white space i threw back in, ended as follows:&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;With Visual C++ 2005, the Standard Template Library (STL) has been re-engineered to work under the .NET Framework. This article, the first in a series, provides a general tour of STL.NET.&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;Talk about a poor relative. In any case, t&lt;/span&gt;&lt;span style="FONT-FAMILY: Tahoma"&gt;his article is culled from a text I am writing on the C++ binding to the CLI, so if you have any concerns or comments or a content wish-list, please drop me a line. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=214536" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Why C++ Supports both Class and Typename for Type Parameters</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/11/212768.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/11/212768.aspx</id><published>2004-08-11T13:32:00Z</published><updated>2004-08-11T13:32:00Z</updated><content type="html">&lt;span style="FONT-SIZE: 12pt"&gt;&lt;font face="Palatino"&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;Recently, someone asked me why we support both class and typename within C++ to indicate a type parameter since the keywords do not hold any platform significance – for example, &lt;/span&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: Tahoma"&gt;class&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt; is not meant to suggest a native type nor is typename meant to suggest a &lt;/span&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: Tahoma"&gt;CLI&lt;/span&gt;&lt;/i&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt; type. Rather, both equivalently indicate that the name following represents a parameterized type placeholder that will be replaced by a user-specfied actual type. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;The reason for the two keywords is historical. In the original template specification, Stroustrup reused the existing class keyword to specify a type parameter rather than introduce a new keyword that might of course break existing programs. It wasn't that a new keyword wasn't considered -- just that it wasn't considered necessary given its potential disruption. And up until the ISO-C++ standard, this was the only way to declare a type parameter. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;Reuses of existing keywords seems to always sow confusion. What we found is that beginners were whether the use of the class constrained or limited the type arguments a user could specify to be class types rather than, say, a built-in or pointer type. So, there was some feeling that not having introduced a new keyword was a mistake.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;During standardization, certain constructs were discovered within a template definition that resolved to expressions although they were meant to indicate declarations. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="codefirstline" style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;template &amp;lt;class T&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;class Demonstration {&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;public:&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;void method() {&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;T::A *aObj; // oops …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="code" style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;// …&lt;/font&gt;&lt;/font&gt;&lt;/p&gt; &lt;p class="codelastline" style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;While the statement containing aObj is intended by the programmer to be interpreted as the declaration of a pointer to a nested type A within the type parameter T, the language grammar interprets it as an arithmetic expression multiplying the static member A of type T with aObj and throwing away the result. Isn't that annoying! (This sort of dilemna is not possible within generics – there is no way to safely verify that any T contains an A so that the runtime can safely construct an instance of the generic type.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="text" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;The committee decided that a new keyword was just the ticket to get the compiler off its unfortunate obsession with expressions. The new keyword was the self-describing typename. When applied to a statement, such as,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="codeoneline" style="MARGIN: 6pt 0in 6pt 0.5in"&gt;&lt;font face="Courier New" size="2"&gt;typename T::A* a6; // &lt;i&gt;declare pointer to &lt;/i&gt;T&lt;i&gt;’s &lt;/i&gt;A&lt;/font&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;it instructs the compiler to treat the subsequent statement as a declaration. Since the keyword was on the payroll, heck, why not fix the confusion caused by the original decision to reuse the class keyword. Of course, given the extensive body of existing code and books and articles and talks and postings using the class keyword, they chose to also retain support for that use of the keyword as well. So that's why you have both. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="textnoindent" style="MARGIN: 6pt 0in"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=212768" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Why C++/CLI Supports both Templates for CLI Types and the CLI Generic Mechanism</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/05/209606.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/05/209606.aspx</id><published>2004-08-06T01:27:00Z</published><updated>2004-08-06T01:27:00Z</updated><content type="html">&lt;P class=textnoindent style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma"&gt;I've been recently puzzling out a strategy for presenting the two mechanisms supporting parameterized types available to the C++/CLI&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;programmer: she can use either the template mechanism adapted for use with CLI types, or the CLI generic mechanism. This is not unique to the support of parameterized types, of course, but it seems a lightening rod for pernicky questions: &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;(1) isn't the support for two mechanisms that are similar in intent but which differ in both gross and subtle semantic behavior confusing for a user? &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;(2) doesn't the dual nature of these constructs increase the liklihood of programmer error? &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;(3) isn't this a canonical illustration of the undisciplined nature of the C++ language design where everything but the kitchen sink seems to get thrown in? you guys just can't get your act together, can you?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;Let's see what kind of answers I can offer. [Disclaimer: of course, these are my thoughts, and do not represent either the corporate views or policies of Microsoft.]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;The C++ binding to the CLI which I refer to as C++/CLI represents an integration of two separate object models: the static object model of native C++ and the dynamic program model of the CLI. We've seen conflicts between these two models before &amp;#8211; in particular between the native and CLI enum, the native and CLI array, and the native and CLI reference class. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;Under the CLI object model, individual languages are &amp;#8211; not to put too fine a point on it &amp;#8211; somewhat diminished &amp;#8211; much as how in a modern country, the individual states while soverign are constrained to the laws of the central authority. For example, the CLI defines the underlying type system within which a language operates, as well as the inheritance model. As we saw in an earlier blog, the CLI does not, for example, support private inheritance, value inheritance (that is, the inheritance of implementation but not of type), or multiple inheritance (MI). While a language can choose to support these aspects of inheritance, that support requires a mapping onto the existing CLI object model because there is no direct support. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;The Eiffel language under CLI, for example, choose to provide an MI mapping because it felt that (a) MI is a valuable inheritance model, and (b) its users would be dimished without its support under the CLI &amp;#8211; that is, it would give its users a dimished programming experience under the CLI than on native platforms, and this would likely deter them from migrating to the CLI itself &amp;#8211; or at least of migrating to the CLI while continuing to exercise their Eiffel expertise and culture.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;We did not feel the same imperative as Eiffel with regards to multiple inheritance. But we did feel that imperative towards deterministic finalization of reference types declared within a local block, and so we provided a mapping of a class destructor to a IDisposable::Dispose() method, which is the CLI pattern of reclaiming resources prior to garbage collection finalization. Similarly, we did feel the imperative towards automatic memberwise copy and initialization &amp;#8211; as supported by a copy assignment operator and copy constructor &amp;#8211; and so we provided a mapping. (But these mappings are constrained by the underlying CLI implementation. We could not map memberwise copy into a value class because we could not guarantee that it could be carried out in all circumstances &amp;#8211; at least that is my understanding. I haven't myself verified that but taken it on faith.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;Again, we did this because without these mappings of essential aspects of the native C++ programming experience, we believe the C++ user would have a diminished experience of programming under the CLI than on the native platform, and that this would deter them from migrating to the CLI &amp;#8211; or at least of migrating to the CLI while continuing to exercise their C++ expertise and culture. The template mechanism is another of the essential aspects of modern C++ programming. We believe its absence would represents a significant hole in quality of programmer life when using C++/CLI. Personally, that is my deep belief. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;So, with regard to parameterized types, it felt imperative that we provide some mechanism beyond what was offerred by the System::Collections namespace. The first mechanim that naturally comes to mind to the C++ programmer, of course, is templates. But what about generics? Why couldn't C++/CLI use generics for containing the CLI types, and leave templates for the non-CLI types? Why map the template mechanism into C++/CLI to support the CLI reference class, value class, interface class, delegate, and function?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;The honest answer is because we were left with no choice. One of the generic talking points in presentations, specifications, and hallway whispering, is that generics, while borrowing from C++ template, "does not suffer many of the complexities" of C++ templates. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;What are considered as &lt;I style="mso-bidi-font-style: normal"&gt;superfluous complexities&lt;/I&gt; of C++ templates and were therefore eliminated from the generic mechanism &amp;#8211; partial template specialization, the ability to inherit from the type parameter, support for non-type and template type parameters, the ability to specialize either an entire or selected members of a template, and so on &amp;#8211; are considered by professional C++ programmers and designers of the language as&lt;I style="mso-bidi-font-style: normal"&gt; essential&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;modern&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;programming&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;design&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;patterns&lt;/I&gt; that are fundamental to existing production code and widely-used libraries, such as the STL, LOKI, and Boost. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;The real problem is that although the C++ community and language designers and implementors have deep experience with parameterized types, that experience was not tapped while the design of generics were underway. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;So, we did not have any choice but to provide support of templates for CLI types and to provide an STL.NET implementation. This is great stuff if you care about C++ and want to see it succeed under .NET. Except for performance issues, C++/CLI, in my biased opinion, is shaping up as the premier C++ experience available. Personally, I'm so keen on the new language that I'm planning to reimplement my mscfront translator into the C++/CLI code from native. I'll be reporting my progress on that in quite some detail in a series of blog entries once I get the C++/CLI text I'm working on in shape. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;So, that's why we have templates. Why did we also provide support for generics? Generics are deeply integrated into the CLI, and for that reason solve a number of problems left unsolved in C++ &amp;#8211; in particular, the instantiation model. Because there is no concept of a runtime within native C++, there is no native concept of how a template is instantiated&lt;A title="" style="mso-footnote-id: ftn1" HREF="/slippman/admin/EditPosts.aspx#_ftn1" name=_ftnref1&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;[1]&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt; &amp;#8211; that is, when the binding of an actual parameter to the formal parameter occurs and to what extent. The work of the ISO committee in this area has not been stellar.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;Generics provides a constraint mechanism, something whose absence is keenly felt in the template mechanism.&lt;A title="" style="mso-footnote-id: ftn2" HREF="/slippman/admin/EditPosts.aspx#_ftn2" name=_ftnref2&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: Tahoma; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;[2]&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt; A generic type is recognized by the CIL &amp;#8211; the intermediate language; a template class is not, and so template classes are not cross-language and, it turns out, not cross-assembly as well. That is to say, every serious CLI language has to provide generic support. And that is what we do. Perhaps if we had been participants in the design, the outcome could have been different. But that, to repeat my aunt's favorite refrain, is water under the bridge.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt"&gt;So, from my perspective, that is why we support both the template and generic solutions for parameterized types, and have tried to integrate them into a elegant symmetry. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-size: 10.0pt"&gt;&lt;o:p&gt;&lt;FONT face=Palatino&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=textnoindent style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="FONT-SIZE: 12pt"&gt;&lt;o:p&gt;&lt;FONT face=Palatino&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;o:p&gt;&lt;FONT face=Palatino size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV style="mso-element: footnote-list"&gt;&lt;BR clear=all&gt;&lt;FONT face=Palatino size=2&gt;
&lt;HR align=left width="33%" SIZE=1&gt;
&lt;/FONT&gt;
&lt;DIV id=ftn1 style="mso-element: footnote"&gt;
&lt;P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt"&gt;&lt;A title="" style="mso-footnote-id: ftn1" HREF="/slippman/admin/EditPosts.aspx#_ftnref1" name=_ftn1&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-FAMILY: Palatino"&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Palatino; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT face=Tahoma&gt;[1]&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-FAMILY: Palatino"&gt;&lt;FONT size=2&gt;&lt;FONT face=Tahoma&gt; Not surprisingly, the vocabulary for the different aspects and actions on a parameterized types are quite different between generics and templates &amp;#8211; and I am not going down that path.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV id=ftn2 style="mso-element: footnote"&gt;
&lt;P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt"&gt;&lt;A title="" style="mso-footnote-id: ftn2" HREF="/slippman/admin/EditPosts.aspx#_ftnref2" name=_ftn2&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT face=Tahoma&gt;[2]&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;FONT size=2&gt;&lt;FONT face=Tahoma&gt; &lt;SPAN style="FONT-FAMILY: Palatino"&gt;Bjarne's original Usenix template paper included a discussion of constraint syntax, which he then chose not to incorporate into the design. It's absence means that there is no way to know prior to actual instantiation whether a type is qualified to be used with a particular template class &amp;#8211; other than examining the source code &amp;#8211; which is not really practicable.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=209606" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Identifying the Candidate Function Set</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/08/01/204829.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/08/01/204829.aspx</id><published>2004-08-02T03:58:00Z</published><updated>2004-08-02T03:58:00Z</updated><content type="html">&lt;P class=textnoindent style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;Sorry it is taking me so long these days. I am in the throes of more formal writing &amp;#8211; a book on our CLI binding for C++, and a series of articles for our Visual C++ MSDN website on STL.NET. And my translation tool is happily going through a formal test cycle &amp;#8211; thank you Mitchell and Arjun &amp;#8211; and so I've been fixing bugs and being a developer once more again. So the blog gets bogged down.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;I thought I would follow up on the issue of overload function resolution. And so this entry discusses how a candidate function list is built up. (I realize this is somewhat esoteric, but. Well, I hope someone finds it worth a spin around the page.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;The first question of course, is, &lt;I style="mso-bidi-font-style: normal"&gt;what the heck is a candidate function list&lt;/I&gt;? Literally, a candidate function list is the set of functions sharing the same name visible at a call point. As we'll see, the complexity, when present, has to do with determining the actual set of visible functions.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;It's always good to begin with a simple example &amp;#8211; hopefully, if we can master this one, our confidence will surge, and we can march on to the question of namespace, qualified type names in the signature of a function, and the using declaration in general. Here is our example,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;void f(); // (1)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;void f( String^ ); // (2)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;void f( const string&amp;amp; ); // (3)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;void f( String^, array&amp;lt;String^&amp;gt;^ ); // (4)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;int main( array&amp;lt;String^&amp;gt; ^args ) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if ( args == nullptr ) &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;handle_invalid_command_line();&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;for each ( String^ s in args )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;f( s );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 1in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;There are four candidate functions to the call of &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;f()&lt;/SPAN&gt; within &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;main()&lt;/SPAN&gt;. By inspection, we can see that only two of them are &lt;I style="mso-bidi-font-style: normal"&gt;viable&lt;/I&gt; &amp;#8211; that is, only the &lt;I style="mso-bidi-font-style: normal"&gt;(2)&lt;/I&gt; and &lt;I style="mso-bidi-font-style: normal"&gt;(3)&lt;/I&gt; instances can match the actual invocation. (And &lt;I style="mso-bidi-font-style: normal"&gt;(2)&lt;/I&gt; is the &lt;I style="mso-bidi-font-style: normal"&gt;best&lt;/I&gt; viable function.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;So that was simple. Things start getting somewhat more complicated if the type of a function argument is declared within a namespace. Let's first look at a fully qualified name. In this case, the functions within the namespace that have the same name as the called function are added to the set of candidate func&amp;shy;tions. For example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;namespace CLITypes &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;{&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;public ref class C {&amp;#8230;};&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void takeC( C^ );&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;// &amp;#8230; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void f( CLITypes::C^ cobj )&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;{&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// ok: calls CLITypes::takeC( C^ ) &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;takeC( cobj ); &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;There is no &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;takeC()&lt;/SPAN&gt; function declared within the global scope in which &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;f() &lt;/SPAN&gt;is defined. There is, as well, no using declaration opening up a namespace. So, on first glance, this appears to be an illegal invocation: the candidate set appears to be empty.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;However, because the argument is qualified to occur within the &lt;I style="mso-bidi-font-style: normal"&gt;CLITypes&lt;/I&gt; namespace, the functions declared within that namespace are considered as well. That is, the full set of candidate functions under this circumstance represents the union of the functions visible at the point of call and the functions declared within the namespaces of the argument types.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;There are three general cases in which functions with the same name do not overload &amp;#8211; at least currently. (There is some activity within the ECMA committee that hasn't jelled as yet one way or another &amp;#8211; at least as far as I'm aware.) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;A derived class function that reuses the name of a base class virtual function &lt;I style="mso-bidi-font-style: normal"&gt;overrides&lt;/I&gt; rather than overloads the base class instance. Except when the &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;new&lt;/SPAN&gt; slot modifier is applied, the derived class instance must conform to the signature of the base class function. It substitutes for the base class instance within the derived class virtual table. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;A derived class function that reuses the name of a non-virtual base class function &lt;I style="mso-bidi-font-style: normal"&gt;hides&lt;/I&gt; rather than overloads the base class instance. The signatures of the base and derived class instance are not considered. This is because the overload candidate set for a function does not extend across scope boundaries. (This is the guy currently under siege, I believe.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l0 level1 lfo1"&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="mso-bidi-font-family: Palatino; mso-fareast-font-family: Palatino"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;A function declared within a local block hides rather than overloads all named instances of that function within the enclosing scopes for the extent of that block. This is the most esoteric of the three cases, so let me provide a quick example,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.8in"&gt;&lt;FONT face="Courier New" size=2&gt;String^ &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;Marshall&lt;/st1:City&gt;&lt;/st1:place&gt;( int ); // (1)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT face="Courier New" size=2&gt;String^ g() {&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// these puppies hide global instance &amp;#8230;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;String^ &lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;Marshall&lt;/st1:City&gt;&lt;/st1:place&gt;( double ); // (2)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;String^ &lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;Marshall&lt;/st1:City&gt;&lt;/st1:place&gt;( char* );&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;// (3)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.8in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return &lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;Marshall&lt;/st1:City&gt;&lt;/st1:place&gt;( 1024 ); // resolves to (2)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.8in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;In this example, the global instance of &lt;st1:place w:st="on"&gt;&lt;st1:City w:st="on"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Marshall&lt;/SPAN&gt;&lt;/st1:City&gt;&lt;/st1:place&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;()&lt;/SPAN&gt; is not visible within &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;g()&lt;/SPAN&gt;; the candidate functions are limited to the two declarations within &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;g()&lt;/SPAN&gt; itself. The &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/SPAN&gt; instance is not a viable candidate function for an actual argument of &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;1024&lt;/SPAN&gt;. This leaves us with instance (2) match the formal parameter of type &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;double&lt;/SPAN&gt; through a standard conversion although the global instance, if considered, represents an exact match.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;The candidate functions also depend on the visibility of &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; declarations at the call point. This is because a using declaration opens up a namespace. For example, &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;namespace libs_R_us {&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int max( int, int );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;double max( double, double );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;char max( char, char );&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void func()&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// namespace functions not visible&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// the three calls resolve to global max( char, char )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 4096, 8192 );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 35.1, 35.9 );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 'J', 'L' );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;In this case, the only function visible is the function declared in global scope. It is therefore the only candidate function, and is the instance invoked by all three calls within &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;func()&lt;/SPAN&gt;. This results the loss of precision in both arithmetic invocations. We have two choices for correcting this, both of which make use of a using directive to open the namespace. The question is where we should place it. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;One possibility is to place using declaration in global scope. For example,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;char max( char, char );&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;using libs_R_us::max; // using declaration&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;All three instances of &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;max()&lt;/SPAN&gt; are now visible within the global scope and are placed in the set of candidate functions. The three invocations are now each an exact match to a separate instance, as follows,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void func()&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 4096, 8192 ); // libs_R_us::max(int,int);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 35.1, 35.9);&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;// libs_R_us::max(double,double);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;max( 'J', 'L' );&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// ::max( char, char );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;Alternatively, we might choose to place the &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declaration&lt;/I&gt; within the local scope of &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;func()&lt;/SPAN&gt;. Why would we do that? Primarily to limit the extent of the changes in our program due to the larger set of candidate functions. By adding to the candidate function set at global scope within an existing program, we are potentially changing the function invoked at each call point that does not involve an exact match. This may be a more invasive change than what we are ready to support. The alternative declaration looks as follows,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void func()&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// local using declaration&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using libs_R_us::max;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// same function calls as above&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;Surprisingly, we get a different the set of candidate functions now. This is because &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declara&amp;shy;tions&lt;/I&gt; nest.&lt;/FONT&gt;&lt;A title="" style="mso-footnote-id: ftn1" href="/slippman/admin/EditPosts.aspx#_ftn1" name=_ftnref1&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Palatino; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;FONT face=Arial&gt;[1]&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;FONT face=Arial&gt; With the &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declaration&lt;/I&gt; in local scope, the global function is now hidden. The only visible functions at the call points are the two declared within the namespace, and so our character comparison resolves to the namespace instance &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;max(int,int)&lt;/SPAN&gt; through a promotion of the two character arguments.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;There are two possible solutions to getting the three functions into the candidate set. We originally choose a nested &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declaration&lt;/I&gt; in order to localize the inclusion of the functions to just the call points within &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;func()&lt;/SPAN&gt;. One solution, of course, is to move it back to global scope. But this opens the entire assembly to potential change. Alternatively, we can add the global instance to our nested set of declarations,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void func()&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// now we have all three in the candidate set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using libs_R_us::max;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;extern char max( char, char );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// same function calls as above&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;The set of candidate functions are therefore the union of the functions visible at the point of the call &amp;#8212; including the functions introduced by &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declarations&lt;/I&gt; and &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;directives&lt;/I&gt; &amp;#8212; and the member functions declared in the namespaces associated with the types of the arguments. For example,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codefirstline style="MARGIN: 6pt 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;namespace basicLib {&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;void print( String^ );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;void print( Object^ );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;namespace matrixLib {&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public ref class Matrix { /* ... */ };&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;void print( Matrix^ );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;void display()&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;using basicLib::print;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;matrixLib::Matrix ^mObj;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print( mObj );&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// matrixLib::print( Matrix^ )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print( "literal" ); // basicLib::print( String^ )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=code style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print( 1024 );&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// basicLib::print( Object^ )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=codelastline style="MARGIN: 0in 0in 12pt 0.5in"&gt;&lt;FONT face="Courier New" size=2&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;Which functions are the candidate functions for the call &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;print(mObj)&lt;/SPAN&gt;? The two &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;basicLib&lt;/SPAN&gt; functions introduced by the local &lt;I style="mso-bidi-font-style: normal"&gt;using&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;declaration&lt;/I&gt; are candidate functions because they are visible at the point of the call. Because the function call argument is of type &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;matrixLib::Matrix&lt;/SPAN&gt;, the &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;print()&lt;/SPAN&gt; function declared within the namespace &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;matrixLib&lt;/SPAN&gt; is also a candidate func&amp;shy;tion. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in"&gt;&lt;FONT face=Arial&gt;Once the candidate functions are identified, the next step &amp;#8211; which begins to involve type checking &amp;#8211; is to determine the viable functions within the candidate set. That topic is a candidate for a subsequent blog.&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="mso-element: footnote-list"&gt;&lt;BR clear=all&gt;&lt;FONT face=Palatino&gt;
&lt;HR align=left width="33%" SIZE=1&gt;
&lt;/FONT&gt;
&lt;DIV id=ftn1 style="mso-element: footnote"&gt;
&lt;P class=MsoFootnoteText style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: justify"&gt;&lt;A title="" style="mso-footnote-id: ftn1" href="/slippman/admin/EditPosts.aspx#_ftnref1" name=_ftn1&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="mso-special-character: footnote"&gt;&lt;SPAN class=MsoFootnoteReference&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;[1]&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;FONT size=2&gt; Using directives do not nest. That is, &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"&gt;using&lt;/SPAN&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'"&gt;libs_R_us&lt;/SPAN&gt;&lt;FONT size=2&gt; makes the namespace members visible &lt;I style="mso-bidi-font-style: normal"&gt;as&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;if&lt;/I&gt; they were declared outside the namespace at the location where the namespace is defined. Therefore, whether the using directive is nested or global makes no difference.&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=204829" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>The Value of a Value Class</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/07/23/193353.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/07/23/193353.aspx</id><published>2004-07-23T16:33:00Z</published><updated>2004-07-23T16:33:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;A reader questions the nature of the value type when he writes,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Sender: Slawomir Lisznianski&lt;BR&gt;=====================================&lt;BR&gt;1) Lack of support for SMFs makes value classes unnatural to use. An example in the C++/CLI spec at page 33 is incorrect, as it uses constructors with value classes. In fact, quite a few value class examples in the specification contradict with paragraph 21.4.1.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;SMF, for the uninitiated, means special member functions, and in this case refers to the constraint on a value class that it cannot declare a default constructor, copy constructor, copy assignment operator, or destructor. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Mechanically, the reason these special member functions are not supported, I am told, is because there exists conditions during run-time in which it is not possible for the compiler to insert the appropriate invocations, and thus it is not possible to guarantee the semantics associated with these member functions. And so their support has been withdrawn completely. I suspect that the examples were written before the withdrawal of the default constructor, and the authors of the spec simply overlooked removing them.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;There are a number of negative responses one can have to this: Disbelief, disgust, savage anger are a few that come to mind. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Another way of looking at this is to consider the why and when these special member functions are not required. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;We do not need a copy constructor nor a copy operator when the aggregate type supports bitwise copy. Similarly, we do not need a destructor when the state of the aggregate type exhibits value semantics. Finally, if the runtime zeros out all state by default, then we do not require a default constructor. (In C++, primitive data types are not automatically zeroed out, and so most of our default constructor use &amp;#8211; but granted, not all &amp;#8211; is used to put the object in an uninitialized state.)&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;That is, a value type in the philosophy of the CLI unified type system is a blitable entity with no internal plumbing, so to speak. That is all it naturally supports. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;You put a pointer in it, you got troubles &amp;#8211; there are no special member functions to provide deep copy semantics or to free the resource addressed prior to the end of its lifetime. Let's not even consider attempting to declare complex member types. That's not what you do with value classes.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;I will claim that they are not unnatural. What is unnatural, but understandable presuming that you have a C++ background, are the sophisticated uses you think to put these rather unsophisticated types. When you think value class, think integer. Then things will begin to click for you.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;I will address your second question in a subsequent blog: &lt;FONT size=2&gt;So what's the rationale for trackable references ... ?&lt;/FONT&gt;&lt;BR&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=193353" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>String Literal Conversion to String: Is It a Disaster?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/07/23/192791.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/07/23/192791.aspx</id><published>2004-07-23T12:49:00Z</published><updated>2004-07-23T12:49:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;A reader asks,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Sender: Jack&lt;BR&gt;&lt;BR&gt;re: String Literals are now a Trivial Conversion to String&lt;BR&gt;&lt;BR&gt;Won't it break most of existing libraries who will try to port to C++/CLI? One override for String^ will break a lot of user code and make calls for the overriden function with string literals look much uglier. Maybe it is better to make two types of string literals differ by, say literal prefix (i.e. old string literals would look like "this" and new ones like c"this")?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As Adam Merz noted in his response to Jack's question of a literal modifier, &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;That is exactly what Managed Extensions for C++ did with the S prefix, and what they are trying to avoid at this point (I would think)...&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Adam is correct. Here is how I described the change in an internal translation guide between the Managed Extensions for C++ and the revised C++/CLI language &amp;#8211; this will give you the historical context for why we made the original change.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;In the original language design, a managed string literal was indicated by prefacing the string literal with an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;String *ps1 = "hello";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;String *ps2 = S"goodbye";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;The performance overhead between the two initializations turns out to be non-trivial, as the following &lt;I style="mso-bidi-font-style: normal"&gt;MSIL&lt;/I&gt; representation demonstrates as seen through &lt;I style="mso-bidi-font-style: normal"&gt;ildasm&lt;/I&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;// String *ps1 = "hello";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;ldsflda&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;valuetype $ArrayType$0xd61117dd&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'?A0xbdde7aca.unnamed-global-0'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;newobj instance void [mscorlib]System.String::.ctor(int8*)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;// String *ps2 = S"goodbye";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;ldstr&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;"goodbye"&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;That&amp;#8217;s a pretty remarkable savings for just remembering [or learning] to prefix a literal string with an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. In the revised V2 language, the handling of string literals is made transparent, determined by the context of use. The &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt; no longer needs to be specified.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;What about cases in which we need to explicitly direct the compiler to one interpretation or another, as in the case of an overloaded pair of functions?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;void f(char*);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;void f(String^);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;f("ABC");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // by default calls f(char*)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;In the revised language, an explicit cast is used rather than the prefix &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Lucida Console'; mso-bidi-font-family: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;f(( String^ )"ABC");&amp;nbsp;// ok: invoked f( String^ )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As you can see, the revised language originally sought merely to correct a failing in the original design &amp;#8211; the surprisingly performance penalty for a user misstep in the declaration of a CLI string literal. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This subsequent refinement during the standardization of the language under ECMA represents imo a rebalancing of the CLI and native type systems -- an acknowledgement of the need for the design to be Janus-faced (an image I introduced in one of the three introductory blogs) &amp;#8211; that is, to look equally on the needs of the CLI and native programmer. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Which brings us back to Jack's original question: isn't this going to blow existing code out of the water? Or, to put it more crudely, isn't this a disaster?&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Well, I don't believe so, although I wasn't part of the decision-making process and since the change is currently undocumented as far as I am aware, I have not seen any analysis of the effect of the language change. So, let me give you my take on the effect, and give my reasoning as to why I don't see it as being quite as dire as does Jack.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;The addition of a trivial conversion of a string literal to String^ is &lt;I style="mso-bidi-font-style: normal"&gt;equivalent&lt;/I&gt; to that of const char* rather than taking precedence. The determination of a best viable function, therefore, results in the introduction of an ambiguity rather than to silently change the resolution (and therefore behavior) of the program. The user would then explicitly cast the invocation to the intended type; admittedly, this could be burdensome, but it is not dangerous. &lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;Under C#, a change in the access level of a class member silently changes the resolution of a named reference in an existing program &amp;#8211; which may be completely unknown to the person making the change. We are not talking here of that level of semantic rupture, but merely the difficulty of accommodating the mechanical importation of native code into the CLI program space.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;So, let us try to address the issue of burden, which is what I suspect this all reduces to. I don't believe it is really all that extensive because the C++ overload mechanism operates by scope rather than signature, and so the set of candidate functions is constrained &amp;#8211; unlike a language like C#, for example, where a change like this would be, I suspect, more severe and difficult to manage. (Again, I am not part of the design process currently and so I haven't drilled down on this as deeply as I otherwise might.)&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1"&gt;Candidate functions are limited by scope. Therefore, the extent of the effect of adding an f(String^) to an existing set of f() is limited to the scope in which it is introduced. &lt;/LI&gt;&lt;/OL&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;To be exhaustive, we would break this down into the possible scope scenarios &amp;#8211; local function, independent class, class hierarchy, namespace, and global scope &amp;#8211; and analyze the extent of impact within each. I have not done that, but I suspect that it is really only the global and namespace introductions that are potentially disruptive and burdensome. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;Class hierarchies are not burdensome because names do not overload across base/derived class boundaries in C++ since they maintain their own scope. Namespaces are potentially burdensome because of using declarations, and the global namespace is burdensome just because it is the global namespace. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a start=2&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1"&gt;the introduction of an f(String^) within a class or class hierarchy is not truly burdensome in its potential introduction of an ambiguity. While it may cause a cascade of ambiguities with the introduction of f(String^) at global scope, or within a heavily-used namespace, the real questions then is a design question, imo. What is the purpose of introducing the f(String^) in a space in which const char* is still heavily used? Perhaps in migrating the existing native code base, we should exercise some design refactoring of the interface?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What is the benefit of supporting both const char* and String in a CLI environment? and so on. &lt;/LI&gt;&lt;/OL&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;So, I think the spirit of the change is in the right direction. The solution isn't perfect, however, since this represents the only potentially truncating trivial conversion &amp;#8211; this is what I mean when I say that imo it is not strictly ISO-C++ conforming: there are no other trivial conversions that suffer a loss of precision &amp;#8211; those are all more costly conversions. Of course, on the other hand, String^ is not ISO-C++, but I am not being that literal here. The problem is that if I place a wide-character in the string literal while it exactly matches String^ in the abstract, in practice, it is first parsed as a const char*, and so the second byte is discarded. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;(Thank you, Dave Waggoner, for pointing out that problem.)&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=192791" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>String Literal Conversion to String: Is It a Disaster?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/07/23/192731.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/07/23/192731.aspx</id><published>2004-07-23T12:33:00Z</published><updated>2004-07-23T12:33:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;A reader asks,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Sender: Jack&lt;BR&gt;&lt;BR&gt;re: String Literals are now a Trivial Conversion to String&lt;BR&gt;&lt;BR&gt;Won't it break most of existing libraries who will try to port to C++/CLI? One override for String^ will break a lot of user code and make calls for the overriden function with string literals look much uglier. Maybe it is better to make two types of string literals differ by, say literal prefix (i.e. old string literals would look like "this" and new ones like c"this")?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As Adam Merz noted in his response to Jack's question of a literal modifier, &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;That is exactly what Managed Extensions for C++ did with the S prefix, and what they are trying to avoid at this point (I would think)...&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Adam is correct. Here is how I described the change in an internal translation guide between the Managed Extensions for C++ and the revised C++/CLI language &amp;#8211; this will give you the historical context for why we made the original change.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;In the original language design, a managed string literal was indicated by prefacing the string literal with an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;String *ps1 = "hello";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;String *ps2 = S"goodbye";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;The performance overhead between the two initializations turns out to be non-trivial, as the following &lt;I style="mso-bidi-font-style: normal"&gt;MSIL&lt;/I&gt; representation demonstrates as seen through &lt;I style="mso-bidi-font-style: normal"&gt;ildasm&lt;/I&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;// String *ps1 = "hello";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;ldsflda&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;valuetype $ArrayType$0xd61117dd&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'?A0xbdde7aca.unnamed-global-0'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;newobj instance void [mscorlib]System.String::.ctor(int8*)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;// String *ps2 = S"goodbye";&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;ldstr&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;"goodbye"&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;That&amp;#8217;s a pretty remarkable savings for just remembering [or learning] to prefix a literal string with an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. In the revised V2 language, the handling of string literals is made transparent, determined by the context of use. The &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt; no longer needs to be specified.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;What about cases in which we need to explicitly direct the compiler to one interpretation or another, as in the case of an overloaded pair of functions?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;void f(const char*);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;void f(String^);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;f("ABC");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // by default calls f(const char*)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;In the revised language, an explicit cast is used rather than the prefix &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;S&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;. For example,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Lucida Console'; mso-bidi-font-family: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;f(( String^ )"ABC");&amp;nbsp;// ok: invoked f( String^ )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As you can see, the revised language originally sought merely to correct a failing in the original design &amp;#8211; the surprisingly performance penalty for a user misstep in the declaration of a CLI string literal. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This subsequent refinement during the standardization of the language under ECMA represents imo a rebalancing of the CLI and native type systems -- an acknowledgement of the need for the design to be Janus-faced (an image I introduced in one of the three introductory blogs) &amp;#8211; that is, to look equally on the needs of the CLI and native programmer. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Which brings us back to Jack's original question: isn't this going to blow existing code out of the water? Or, to put it more crudely, isn't this a disaster?&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Well, I don't believe so, although I wasn't part of the decision-making process and since the change is currently undocumented as far as I am aware, I have not seen any analysis of the effect of the language change. So, let me give you my take on the effect, and give my reasoning as to why I don't see it as being quite as dire as does Jack.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;The addition of a trivial conversion of a string literal to String^ is &lt;I style="mso-bidi-font-style: normal"&gt;equivalent&lt;/I&gt; to that of const char* rather than taking precedence. The determination of a best viable function, therefore, results in the introduction of an ambiguity rather than to silently change the resolution (and therefore behavior) of the program. The user would then explicitly cast the invocation to the intended type; admittedly, this could be burdensome, but it is not dangerous. &lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;Under C#, a change in the access level of a class member silently changes the resolution of a named reference in an existing program &amp;#8211; which may be completely unknown to the person making the change. We are not talking here of that level of semantic rupture, but merely the difficulty of accommodating the mechanical importation of native code into the CLI program space.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;So, let us try to address the issue of burden, which is what I suspect this all reduces to. I don't believe it is really all that extensive because the C++ overload mechanism operates by scope rather than signature, and so the set of candidate functions is constrained &amp;#8211; unlike a language like C#, for example, where a change like this would be, I suspect, more severe and difficult to manage. (Again, I am not part of the design process currently and so I haven't drilled down on this as deeply as I otherwise might.)&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1"&gt;Candidate functions are limited by scope. Therefore, the extent of the effect of adding an f(String^) to an existing set of f() is limited to the scope in which it is introduced. &lt;/LI&gt;&lt;/OL&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;To be exhaustive, we would break this down into the possible scope scenarios &amp;#8211; local function, independent class, class hierarchy, namespace, and global scope &amp;#8211; and analyze the extent of impact within each. I have not done that, but I suspect that it is really only the global and namespace introductions that are potentially disruptive and burdensome. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;Class hierarchies are not burdensome because names do not overload across base/derived class boundaries in C++ since they maintain their own scope. Namespaces are potentially burdensome because of using declarations, and the global namespace is burdensome just because it is the global namespace. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;OL style="MARGIN-TOP: 0in" type=a start=2&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list 1.0in; mso-list: l0 level2 lfo1"&gt;the introduction of an f(String^) within a class or class hierarchy is not truly burdensome in its potential introduction of an ambiguity. While it may cause a cascade of ambiguities with the introduction of f(String^) at global scope, or within a heavily-used namespace, the real questions then is a design question, imo. What is the purpose of introducing the f(String^) in a space in which const char* is still heavily used? Perhaps in migrating the existing native code base, we should exercise some design refactoring of the interface?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What is the benefit of supporting both const char* and String in a CLI environment? and so on. &lt;/LI&gt;&lt;/OL&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;So, I think the spirit of the change is in the right direction. The solution isn't perfect, however, since this represents the only potentially truncating trivial conversion &amp;#8211; this is what I mean when I say that imo it is not strictly ISO-C++ conforming: there are no other trivial conversions that suffer a loss of precision &amp;#8211; those are all more costly conversions. Of course, on the other hand, String^ is not ISO-C++, but I am not being that literal here. The problem is that if I place a wide-character in the string literal while it exactly matches String^ in the abstract, in practice, it is first parsed as a const char*, and so the second byte is discarded. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;(Thank you, Dave Waggoner, for pointing out that problem.)&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=192731" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>String Literals are now a Trivial Conversion to String</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/07/19/187758.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/07/19/187758.aspx</id><published>2004-07-19T16:31:00Z</published><updated>2004-07-19T16:31:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;There was a recent internal thread on the resolution of the following set of overloaded member functions of a reference class R. It represents a change in the earlier definition of C++/CLI, and a difference in type behavior that I reported in an earlier blog, and so I believe it is worth discussing. Here is the code snippet,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;public ref class R {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;public:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; void foo( String^ );&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; void foo( const char* );&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;void bar( R^ r )&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; // which one?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp; r-&amp;gt;foo( "abc" );&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The question of the moment is, which instance of &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;foo()&lt;/SPAN&gt; is invoked? Since there is more than one instance, this requires the function overload resolution algorithm being applied to the call. The presumption of this blog entry and the few that follow this is that the majority of readers are likely unsure how to formally think through the algorithm. What I'd ask you to do before reading on is decide what you believe is the correct program behavior and have an explanation clear in your mind.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;T&lt;SPAN style="COLOR: black"&gt;he formal resolution of an overload function involves three steps. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; COLOR: black; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;The collection of the candidate functions&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;. The candidate functions are those methods within the scope that lexically match the name of the function being invoked. For example, since &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;foo()&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt; is invoked through an instance of &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;R&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;, all named functions &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;foo&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt; that are not a member of &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;R&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt; (or of its base class hierarchy) are &lt;I style="mso-bidi-font-style: normal"&gt;not&lt;/I&gt; candidate functions. In our example, there are two candidate functions. These are the two member functions of &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;R&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt; named &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;foo&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;.&lt;/SPAN&gt; A call can fail during this phase if the candidate function set is null.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=textnoindent style="MARGIN: 6pt 0in 6pt 0.5in; TEXT-INDENT: -0.25in; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-weight: bold"&gt;The set of viable functions from among the candidate function&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-weight: bold"&gt;. A viable function is one that &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;can be invoked with the arguments specified in the call, given the number of arguments and their types. In our example, both candidate functions are also viable functions. A call can fail during this phase if the viable function set is null. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=3&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; COLOR: black; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="COLOR: windowtext"&gt;Select the function that represents the best match of the call&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: windowtext"&gt;. This is done by ranking the conversions&lt;B style="mso-bidi-font-weight: normal"&gt; &lt;/B&gt;applied to transform the arguments to the type of the viable function parameters. This is relatively straight-forward with a single parameter function; it becomes somewhat more complex when there are multiple parameters. A call can fail during this phase if there is no best match. That is, if the conversions necessary to transform the type of the actual argument to the type of the formal parameter are equally good. The call is then flagged as ambiguous. &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;In an earlier existence of the language, the resolution of this call invoked the &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char*&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; instance as the best match. In the present version of the language, the conversion necessary to match &lt;I style="mso-bidi-font-style: normal"&gt;"abc"&lt;/I&gt; to &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char*&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; and &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;String^&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; are now equivalent &amp;#8211; that is, equally good &amp;#8211; and so the call is flagged as bad &amp;#8211; that is, as ambiguous. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;This leads us to two questions:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; COLOR: black; tab-stops: list .5in; mso-list: l1 level1 lfo2"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;What is the type of the actual argument, "abc"?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; COLOR: black; tab-stops: list .5in; mso-list: l1 level1 lfo2"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;What is the algorithm for determining when one type conversion is better than another?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;The type of the string literal "abc" is &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char[4]&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; &amp;#8211; remember, there is an implicit null terminating character at the end of every string literal. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;The algorithm for determining when one type conversion is better than another involves placing the possible type conversions in a hierarchy. Here is my understanding of that hierarchy &amp;#8211; all these conversions, of course, are implicit. Using an explicit cast notation overrides the hierarchy similar to the way parentheses overrides the usual operator precedence of an expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l2 level1 lfo3"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;An &lt;I style="mso-bidi-font-style: normal"&gt;exact&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;match&lt;/I&gt; is best. Surprisingly, for an argument to be an exact match, it does not need to exactly match the parameter type; it just needs to be close enough. This is the key to understanding what is going on in this example, and how the language has been changed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l2 level1 lfo3"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;A &lt;I style="mso-bidi-font-style: normal"&gt;promotion&lt;/I&gt; is better than a conversion. For example, promoting a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;short&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; to an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; is better than converting an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; into a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;double&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l2 level1 lfo3"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;A &lt;I style="mso-bidi-font-style: normal"&gt;standard&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;conversion&lt;/I&gt; is better than a boxing conversion. For example, converting an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; into a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;double&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; is better that boxing an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; into an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Object&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l2 level1 lfo3"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;4.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;A &lt;I style="mso-bidi-font-style: normal"&gt;boxing&lt;/I&gt; conversion is better than an implicit user-defined conversion. For example, boxing an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; into an &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;Object&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; is better than applying a conversion operator of a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'"&gt;SmallInt&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; value class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=text style="MARGIN: 6pt 0in 6pt 0.8in; TEXT-INDENT: -0.25in; tab-stops: list .8in; mso-list: l2 level1 lfo3"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;SPAN style="mso-list: Ignore"&gt;5.&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;An &lt;I style="mso-bidi-font-style: normal"&gt;implicit&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;user&lt;/I&gt;-&lt;I style="mso-bidi-font-style: normal"&gt;defined&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;conversion&lt;/I&gt; is better than no conversion at all. An implicit user-defined conversion is the last exit before &lt;I style="mso-bidi-font-style: normal"&gt;Error&lt;/I&gt; (with the caveat that the formal signature might contain a &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Times New Roman'"&gt;param&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; array or &lt;I style="mso-bidi-font-style: normal"&gt;ellipsis&lt;/I&gt; at that position).&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black"&gt;So, what does it mean to say that an exact match isn't necessarily exactly a match? For example, &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'"&gt;const&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'"&gt;char[4]&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; does not exactly match either &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'"&gt;const&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'"&gt;char*&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt; or &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'"&gt;String^&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;, and yet the ambiguity of our example is between two conflicting exact matches!&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;An exact match, as it happens, includes a number of &lt;I style="mso-bidi-font-style: normal"&gt;trivial&lt;/I&gt; conversions. There are four trivial conversions under &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt;ISO-C++&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; that can be applied and still qualify as an exact match. Three are referred to as &lt;I style="mso-bidi-font-style: normal"&gt;lvalue&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;transformations&lt;/I&gt;. A fourth type is called a &lt;I style="mso-bidi-font-style: normal"&gt;qualification&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;conversion&lt;/I&gt;. The three lvalue transformations are treated as a &lt;I style="mso-bidi-font-style: normal"&gt;better&lt;/I&gt; exact match than one requiring a qualification conversion. &lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;One form of the lvalue transformation is the &lt;I style="mso-bidi-font-style: normal"&gt;native-array-to-pointer&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;conversion&lt;/I&gt;. This is what is involved in matching a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char[4]&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; to &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char*&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;. Therefore, the match of &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;foo("abc")&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; to &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;foo(const&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char*)&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; is an exact match. In the earlier incarnations of our &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt;C++/CLI&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; language, this was the best match, in fact.&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;For the compiler to flag the call as ambiguous, therefore, requires that the conversion of a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;const&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;char[4]&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; to a &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;String^&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; also be an exact match through a trivial conversion, something that is not currently documented in public language specification, so we can all be forgiven for being surprised at the current behavior.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;So this represents a &lt;I style="mso-bidi-font-style: normal"&gt;fifth&lt;/I&gt; trivial conversion, one unique to &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt;C++/CLI&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt;. If you think about it, it makes good sense &amp;#8211; in the same vein as having a &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt;CLI&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;enum&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; more nearly match &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold"&gt;Object&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; than an arithmetic type. But it also represents the difficulties facing the experienced &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: black; mso-bidi-font-weight: bold"&gt;C++&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="COLOR: black; mso-bidi-font-weight: bold"&gt; programmer in crossing over from &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:place w:st="on"&gt;&lt;st1:State w:st="on"&gt;Kansas&lt;/st1:State&gt;&lt;/st1:place&gt; to Oz. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="COLOR: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=187758" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Factor, Don't Complicate</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/06/04/148586.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/06/04/148586.aspx</id><published>2004-06-04T13:50:00Z</published><updated>2004-06-04T13:50:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;A reader asks the following question,&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Sender: bv&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;re: A Question about Copy Constructors in C++/CLI&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Ok, i have a question.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;What happens if: suppose you want to make a shallow copy. Ex:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;ClassX obj(somePtr);//internally obj.m_ptr = SomePtr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Now&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;ClassX obj2(obj);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;What problems can occur in such cases?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;because now neither obj nor obj2 owns the member ptr. so none should destroy them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;And i want that, only obj should be able to modify the ptr and not obj2. How will i do it?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The purpose of a copy constructor (and copy assignment operator) is to allow users to overwrite the default behavior. In the C language, the default behavior of copying one aggregate object with another is bitwise copy. In the original C++ implementation, this was also the behavior of copying one class object with another. However, the greater functionality of a class over that of a C struct required changing the default behavior to that of memberwise copy &amp;#8211; that is, to recognize the integrity of member and base class sub-objects. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The complexity within C++ of copying one class object with another falls into two general categories &amp;#8211; at least into two general categories that I wish to address: &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;When we use primitive members such as pointers that reflect shallow copy and fall outside the constructor as resource acquisition pattern. In effect, we have to provide our own deep copy semantics.&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.25in"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1 start=2&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;When we decide to implement complex behavioral patterns, such as, for example, copy on write, reference counting, and all sorts of neat abstract relationships that fall outside the default copy behavior.&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The default copy behavior of CLI reference types is shallow copy. That is, a reference type is a duple consisting of a named tracking handle and an object allocated on the CLI heap. The copying of one tracking handle to another results in both handles addressing the same heap object. In a garbage collection environment, the too-early destruction problem of ISO-C++ goes away. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;So, with that background, let&amp;#8217;s go to the reader&amp;#8217;s question.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;ClassX obj(somePtr);&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;//internally obj.m_ptr = SomePtr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;ClassX obj2(obj);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;What problems can occur in such cases?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Well, the first thing is, I will presume that this is an ISO-C++ class, not a C++/CLI class given the emphasis on pointers. So we are talking about a &lt;I style="mso-bidi-font-style: normal"&gt;classic&lt;/I&gt; solution &amp;#8211; that is, with memberwise default behavior. The minimal class we can extrapolate from this small code sample is,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;class X &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;T * m_ptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;public: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// &lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;ClassX obj(somePtr);&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN lang=FR style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: FR"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;X( T * somePtr ) : m_ptr( somePtr ){}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN lang=FR style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: FR"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This is all that is required to support the examples provided by the writer. An initialization of one X object with another, such as&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;X x1( myT );&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;X x2( x1 );&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;by default results in the bitwise copy of &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;x2&lt;/SPAN&gt; with &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;x1&lt;/SPAN&gt; without the explicit invocation of a synthesized copy constructor, with &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;x2.m_ptr&lt;/SPAN&gt; holding the same address as &lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;x1.m_ptr&lt;/SPAN&gt;.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The reader then asks,&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;What problems can occur in such cases?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;because now neither obj nor obj2 owns the member ptr. so none should destroy them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;And i want that, only obj should be able to modify the ptr and not obj2. How will i do it?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Well, because both objects manipulate the same object through their pointer member, any write may come as a surprise; moreover, if they are on separate threads, there is a need for locking on write operations. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As the user notes, it is not a good idea for either x1 or x2 to destroy the object addressed without somehow synchronizing it with the other &amp;#8211; again, this is exactly the problem that garbage collection solves, removing the burden on the user.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;To synchronize the destruction, one has to come up with some form of reference counting mechanism &amp;#8211; the first discussion of that in C++ was James Coplien&amp;#8217;s Advanced C++. Bjarne provides an example in his C++ Programming Language. I&amp;#8217;m not going to go into the actual implementation. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The second question is, how should one restrain changes to the object that are pointed to by multiple instances of class X such that there is one `master&amp;#8217; and many &amp;#8230; well, readers. The best way, in my opinion, to do this is to factor the design into two classes &amp;#8211; and allowing the readers read-only access rather than holding a pointer to it. Otherwise, you have a rather clunky design in which the object has to ask, am I allowed to modify this guy I point to? Does the writer, or master, still exist? [probably can&amp;#8217;t answer that] &amp;#8211; and there is no notification semantics that one could employ, etc. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;So, the answer to the second question is, come up with a design in which the characteristics of the one writer or many readers is built into the types; otherwise,&amp;nbsp;the class&amp;nbsp;is non-intuitive and will likely confuse users and be a cause of error and frustration.&amp;nbsp;&amp;nbsp;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148586" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>Putting C++ and the CLI in Perspective</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/06/04/148517.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/06/04/148517.aspx</id><published>2004-06-04T12:36:00Z</published><updated>2004-06-04T12:36:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;A surprising thread that has emerged has to do with libraries. Here is an representative example, &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Sender: Dobes&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;=====================================&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;re: Towards a Natural Theory of Programming Languages&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;I also think that the survival of a language is also more an issue of libraries than of language.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;I prefer Java because it has gui,threading, sockets, class loading, etc. all built in to the standard library.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since these are the primary features that differ between platforms, the majority of code can be written to depend only on these APIs, and in doing so be automatically cross platform.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;C++ could push its way back into usefulness if it, too, required that all C++ implementations provided a standard API for threading, I/O, loadable modules, and user interfaces.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I doubt they will - these are very difficult to implement in a language without garbage collection.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Many of the issues just cannot be addressed to satisfaction for all programs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Java and C++ exist in different pockets of the programming community. Telephony, Aerospace, Animation, for example, are all C++ domains. JPL, for example, is doing its 2009 onboard control system in C++ not Java because Java is not performant. So, to say that C++ `could push its way back to usefulness&amp;#8217; is not a quantifiable statement, is not currently true; it is simply an expression of how the writer personally feels. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;The environment in which ISO-C++ has a competitive disadvantage is in the dynamic programming paradigm which is imo currently exemplified by CLI and ok, Java. This is why we have been working so hard for the last two years to &amp;#8211; ok &amp;#8211; adapt ISO-C++ into C++/CLI which integrates the standard C++ Object model with the CLI Object model. We believe that we have established a competitive baseline language that is as good as Java in this domain. That is our hypothesis, in any case &amp;#8230; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;The argument about libraries is both valid and moot. It is valid because I agree with it &lt;/SPAN&gt;&lt;/I&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;&lt;SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;J&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;. It is moot because the whole elegance of the CLI is that it provides a language-independent class library that provides everything Dobes, above, lists. If you prefer to write in standard ML of &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:State w:st="on"&gt;&lt;st1:place w:st="on"&gt;New Jersey&lt;/st1:place&gt;&lt;/st1:State&gt;, or in Python, or in, let the bits preserve you, Eiffel, you get the same class library and tools operating on a common intermediate language. We&amp;#8217;re just beginning to do nifty things with this &amp;#8230; not just in C++, but within the programming community at large and within Microsoft Research and in the academic community.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;While I have a preference for C++, obviously, its continued existence &amp;#8211; as with any language &amp;#8211; is finite. While we would like to extend its usefulness within the CLI &amp;#8211; particularly since we see the CLI becoming the dominant environment &amp;#8211; whether we succeed in that or not is the zest of our coming to work each day. You can&amp;#8217;t know if we are going to fail or not beforehand &amp;#8230; folks that think everything is decided already or by rudeness try to eliminate our efforts are inconsequential. We know that there is a lot of work to be done, and I don&amp;#8217;t have all the answers. No one here can guarantee that. But we&amp;#8217;re privileged enough to have the opportunity. I&amp;#8217;m quite grateful for that.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=148517" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry><entry><title>System::String -&gt; std::string</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx" /><id>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx</id><published>2004-06-02T18:56:00Z</published><updated>2004-06-02T18:56:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;A reader asks,&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Sender: Erik Brendengen&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Is there an easy way to convert from String^ to std::string?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Does String ^s = std::string( &amp;#8220;bla&amp;#8221;).c_str(); work the other way?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This is a FAQ, one that I myself bumped into when I had to pass a System::String retrieved from System::Windows::Forms::TextBox to a native program that expected a std::string. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;There are generally two conversion strategies, depending on which side of the managed/native fence you wish to do the conversion work. Here are two methods making use of the PtrToStringChars( String^ ) utility from the vcclr.h header file that is part of Visual C++. Note that these are written in the new C++/CLI syntax &amp;#8211; and that these are adapted from an internal FAQ ...&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;&lt;PRE style="MARGIN-LEFT: 0.25in"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.25in"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;#include &amp;lt;vcclr.h&amp;gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.25in"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;#include &amp;lt;string&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.25in"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=2&gt;using namespace System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN style="FONT-FAMILY: 'Palatino Linotype'"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;bool To_CharStar( String^ source, char*&amp;amp; target )&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;{&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pin_ptr&amp;lt;const wchar_t&amp;gt; wch = PtrToStringChars( source );&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int len = (( source-&amp;gt;Length+1) * 2);&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;target = new char[ len ];&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return wcstombs( target, wch, len ) != -1;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;o:p&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;bool To_string( String^ source, string &amp;amp;target )&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;{&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pin_ptr&amp;lt;const wchar_t&amp;gt; wch = PtrToStringChars( source );&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int len = (( source-&amp;gt;Length+1) * 2);&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char *ch = new char[ len ];&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;bool result = wcstombs( ch, wch, len ) != -1;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;target = ch;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;delete ch;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;return result;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN-LEFT: 0.5in"&gt;&lt;FONT size=2&gt;}&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As to the second question, does String^ s = ns.c_str() work? Yes.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=147090" width="1" height="1"&gt;</content><author><name>slippman</name><uri>http://blogs.msdn.com/members/slippman.aspx</uri></author></entry></feed>