Opened 9 years ago

Last modified 9 years ago

#6100 closed enhancement

Disallow copy and assignment in OGRFeatureDefn — at Version 1

Reported by: Kurt Schwehr Owned by: warmerdam
Priority: normal Milestone: 2.1.0
Component: default Version: svn-trunk
Severity: normal Keywords:
Cc:

Description (last modified by Kurt Schwehr)

This is a change I'd like to add to make sure that sneaky copy or assignment usages do not creep in on OGRFeatureDefn where reference counting is happening. Any reason not to add the pre-C++11 version of restriction?

  • ogr/ogr_feature.h

     
    252252
    253253    static OGRFeatureDefn  *CreateFeatureDefn( const char *pszName = NULL );
    254254    static void         DestroyFeatureDefn( OGRFeatureDefn * );
     255
     256  private:
     257    // Disable copy and assignment to prevent reference counting problems.
     258    OGRFeatureDefn( const OGRFeatureDefn &that );  // No implementation.
     259    OGRFeatureDefn &operator=( const OGRFeatureDefn& );  // No implementation.
    255260};
    256261
    257262/************************************************************************/

Someday when C++11 is allowed, this would be

OGRFeatureDefn( const OGRFeatureDefn &that ) = delete;
OGRFeatureDefn &operator=( const OGRFeatureDefn& ) = delete;

Which could be behind an if:

#if __cplusplus >= 201103L
    OGRFeatureDefn( const OGRFeatureDefn &that ) = delete;
    OGRFeatureDefn &operator=( const OGRFeatureDefn & ) = delete;
#else
  private:
    // Disable copy and assignment to prevent reference counting problems.
    OGRFeatureDefn( const OGRFeatureDefn &that );  // No implementation.
    OGRFeatureDefn &operator=( const OGRFeatureDefn & );  // No implementation.
#endif

http://stackoverflow.com/questions/6077143/disable-copy-constructor

Change History (1)

comment:1 by Kurt Schwehr, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.