M
Markus Svilans
Hi,
I have a weird problem in a virtual method. The original method code
raises an access violation when it is run. The solution to the problem
is to declare a dummy integer inside the virtual method. Then the
access violation no longer occurs!
The following class (condensed from the NetCDF C++ interface):
class NcVar : public NcTypedComponent
{
public:
// This method implements an abstract method in NcTypedComponent
virtual NcType type() const;
private:
int dim_to_index(NcDim* rdim);
int the_id;
};
Original implementation of type():
NcType NcVar::type() const
{
// nc_inq_vartype is a library function that works normally
// outside of this method
nc_type typ;
nc_inq_vartype(the_file->id(), the_id, &typ);
return (NcType)typ;
}
Running this code raises an access violation. Calling the exact same
code outside of the method works perfectly.
Modified implementation of type():
NcType NcVar::type() const
{
int x; // That's right, adding this makes it work
nc_type typ = 0;
nc_inq_vartype(the_file->id(), the_id, &typ);
return (NcType)typ;
}
Adding the "int x" makes the code run, without any access violations!
A few other of the virtual methods in other classes have a similar
problem.
What's going on here?
FYI, this code is from the NetCDF C++ interface. I am trying to use it
with Borland C++ Builder 6. I did not write the NetCDF C++ interface,
but I am trying to use it as-is, and the access violation problem has
been driving me nuts.
Any help would be appreciated.
Regards,
Markus.
I have a weird problem in a virtual method. The original method code
raises an access violation when it is run. The solution to the problem
is to declare a dummy integer inside the virtual method. Then the
access violation no longer occurs!
The following class (condensed from the NetCDF C++ interface):
class NcVar : public NcTypedComponent
{
public:
// This method implements an abstract method in NcTypedComponent
virtual NcType type() const;
private:
int dim_to_index(NcDim* rdim);
int the_id;
};
Original implementation of type():
NcType NcVar::type() const
{
// nc_inq_vartype is a library function that works normally
// outside of this method
nc_type typ;
nc_inq_vartype(the_file->id(), the_id, &typ);
return (NcType)typ;
}
Running this code raises an access violation. Calling the exact same
code outside of the method works perfectly.
Modified implementation of type():
NcType NcVar::type() const
{
int x; // That's right, adding this makes it work
nc_type typ = 0;
nc_inq_vartype(the_file->id(), the_id, &typ);
return (NcType)typ;
}
Adding the "int x" makes the code run, without any access violations!
A few other of the virtual methods in other classes have a similar
problem.
What's going on here?
FYI, this code is from the NetCDF C++ interface. I am trying to use it
with Borland C++ Builder 6. I did not write the NetCDF C++ interface,
but I am trying to use it as-is, and the access violation problem has
been driving me nuts.
Any help would be appreciated.
Regards,
Markus.