NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Perhaps you are using an outdated version of the new c++ interface? In the current version, the copy constructor and copy assignment operator are disabled, precisely to avoid the kind of bugs you are running into. In the latest version, the following code will not compile: foo = NcFile("blah.nc", NcFile::replace); (see this commit of 9 december 2013, https://github.com/Unidata/netcdf-cxx4/commit/cf35fe8980479d8a414fdd8828d74bfc89cda036 ) When you write foo = NcFile("blah.nc", NcFile::replace); A temporary NcFile object is created, then copy-assigned to foo, and then destructed. The destructor of the temporary NcFile closes the NetCDF file, and foo now holds an invalid NetCDF id (the id of the file that was just closed), which causes errors when you try to use it later on. This is likely also why you ran into trouble using NcFiles as class members. With c++11, it would be nice to have move assignment and construction for NcFile. Until then, your suggestion of using unique_ptr<NcFile> is a good workaround. cheers, Thomas From: Jack Stalnaker <jack.stalnaker@xxxxxxxxx> Subject: Re: [netcdfgroup] c++ NcFile assignment doesn't work Date: Fri, 24 Apr 2015 14:22:37 -0500
_______________________________________________ netcdfgroup mailing list netcdfgroup@xxxxxxxxxxxxxxxxFor list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/
netcdfgroup
archives: