This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: Harsh Anand <address@hidden> >Subject: Re: 20000802: netcdf 3.5-beta3 installation problem on IBM SP >Organization: LBNL/NERSC >Keywords: 200008022147.e72LljT08254 netCDF 3.5-beta3 C++ friend Harsh, > Sorry for getting back to you this late. It took very long to > get the standard reference from the IBM tech support. > Please let me know if this answers your query. Thanks for sending this. It does answer my question, so I've changed the code in netCDF 3.5 as a result. Now it should compile on IBM platforms without the C++ error you were seeing. It will be in the next beta release, which I'm hoping to get out this week or early next week ... --Russ Here is their response: >where in the standard the following syntax is disallowed: >friend NcFile::NcFile( const char *, FileMode, size_t*, size_t); "The solution to your question is the following section of the C++ Standard 12.1, paragraph 1. "Constructors do not have names." Reading further into this paragraph it states that a constructor is indicated with a special syntax. "friend" is not in this syntax so it cannot be used in a constructor declaration/definition. Thus, it is impossible to have a constructor that is a friend. That said, the same effect can be had by making the class (for the constructor) a friend so that the constructor would also be granted friendship." For your reference here is the URL for the C++ standard: http://www.dfv.rwth-aachen.de/doc/c++std/special.html#class.conv.ctor Regards. Harsh > >From: Harsh Anand <address@hidden> > >Subject: netcdf 3.5-beta3 installation problem on IBM SP > >Organization: LBNL/NERSC > >Keywords: 200008022147.e72LljT08254 netCDF 3.5-beta3 > > Hi Harsh, > > > I got errors like > > > > xlC -c -I../libsrc -I. -DNDEBUG netcdf.cpp > > "netcdfcpp.h", line 156.10: 1540-0133 (S) The attributes "friend" are > > not allowed. > > > > installing C++ interface on the IBM SP3 we have at NERSC Lawrence > > Berkeley Lab: > > > > FYI -- IBM tech support folks tell me that it is not a bug. According > > to the > > standard "The attributes "friend" are not allowed". Could you > > please suggest any workaround for this problem? > > I have successfully compiled this program using KAI C++ compiler. > > See a previous message for a workaround: > > http://www.unidata.ucar.edu/glimpse/netcdf/3814 > > But I don't understand how this could be non-standard C++. The draft > standard available from > > http://www.cygnus.com/misc/wp/dec96pub/access.html includes the > > following example: > > 4 When a friend declaration refers to an overloaded name or operator, > only the function specified by the parameter types becomes a friend. > A member function of a class X can be a friend of a class Y. [Exam- > ple: > class Y { > friend char* X::foo(int); > // ... > }; > > which uses the same syntax we use. Is it that you can't declare a > private constructor to be a friend? If so, I haven't seen that > restriction explicitly stated anywhere. Can you find out where in the > standard this syntax is disallowed, since no other C++ compiler we > have tried objects to it? > > A less heavy-handed workaround would be to declare the whole NcFile > class to be a friend rather than just particular member functions, > that is use > > friend NcFile; > > instead of > > friend NcFile::NcFile( const char *, FileMode, size_t*, size_t); > friend NcBool NcFile::sync( void ); > friend NcDim* NcFile::add_dim( NcToken, long ); > // to delete dimensions, since destructor is private > friend NcBool NcFile::close( void ); > > and similarly for other places where the compiler objects to the > declarations of particular member functions as friends. But I don't > understand why this should be necessary ... > > --Russ -- Harsh Anand ---------------------------------- address@hidden -| NERSC User Services phone: (510) 486-5575 | Lawrence Berkeley Lab Fax: (510) 486-7520 | Univ. of California, Berkeley ------------------------------------