C#
  Home arrow C# arrow Page 5 - Satview: Pointer Perfect, Part 3
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Satview: Pointer Perfect, Part 3
By: J. Nakamura
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2004-12-13

    Table of Contents:
  • Satview: Pointer Perfect, Part 3
  • Functions
  • Smart pointers
  • The meaning of ownership
  • The auto_ptr is counter-intuitive
  • The concept of source and sink

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Satview: Pointer Perfect, Part 3 - The auto_ptr is counter-intuitive


    (Page 5 of 6 )

    Because of the requirement that there can be only one owner of a resource when using the auto_ptr, the copy constructor of an auto_ptr modifies the object that is used to initialize the new object, and the assignment operator modifies the right-hand side of the assignment. Yes, you read that right! It is up to you to make sure that the auto_ptr that lost ownership and is now holding NULL, is no longer dereferenced. This behavior is quite counter-intuitive, since you would expect a copy constructor and assignment operator to look like this:

    MyClass(MyClass const &other);
    MyClass& operator=(MyClass const &rhs);

    Instead, when we look at the std::auto_ptr as it comes with Microsoft Visual Studio .NET 2003, it looks like this:

    auto_ptr(auto_ptr<_Ty>& _Right)
    auto_ptr<_Ty>& operator=(auto_ptr<_Other>& _Right)

    Spot the difference! That’s right, it violates general behavior, because the function parameters have no const modifier and are being changed in both functions! The fact that they have to be changed (the pointer they held is set to NULL to indicate they lost ownership), prevents the function arguments from being const. This can cause a lot of confusion!

    More C# Articles
    More By J. Nakamura


     

    C# ARTICLES

    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT