Definition of destructor of materials class #27432
-
I have a special case where I have to declare a pointer to an external API in the constructor. I need to explicitly free the API pointer and I think I need to use the destructor class. (This is the continuation of discussion #24588) Can you provide me a example of the destructor ? Let's say, this is my #pragma once
#include "Material.h"
#include "DerivativeMaterialInterface.h"
#include <vector>
#include "pfm_sdk.h"
class GmTernary : public DerivativeMaterialInterface<Material>
{
public:
static InputParameters validParams();
GmTernary(const InputParameters & parameters);
protected:
virtual void computeQpProperties();
private:
PFM_SDK* _m_pfm_sdk;
}; And this is my constructor GmTernary::GmTernary(const InputParameters & parameters)
: DerivativeMaterialInterface<Material>(parameters)
{
_m_pfm_sdk = NULL;
_m_pfm_sdk = Define_PFM_SDK( &m_args, calculate_parallel_tangent, msg_char); // Allocated _m_pfm_sdk pointer.
} From the API libray, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hello You can call this API in the destructor of your new class. You ll want to make sure the default class destructor is mostly still called though. You can do that by calling the base class destructor in your class destructor Guillaume |
Beta Was this translation helpful? Give feedback.
nevermind you dont need to call the parent class destructor, that's done automatically
https://isocpp.org/wiki/faq/dtors#cant-overload-dtors