0

I am using double pointer member in base class. but in derived class constructor I am getting error

error: no matching function for call to ‘Layer::Layer(tensor&, float&)’ :Layer(**tn, **input)

// base class
class Layer
{
    protected:
        struct tensor **tensor_node;
        float **tensor_input_activation;

    public:

        /*  ***Constructor*** */
        Layer(struct tensor **, float **);
};

Layer::Layer(struct tensor **tn, float **input)
{
    *tensor_node = *tn;
    *tensor_input_activation = *input;
}

// derived class from Layer
class BatchNormalization : public Layer
{
    string layer_name;

    public:
        /* ***Constructor*** */
        BatchNormalization(struct tensor **, float **, string);

        /* ***Member_function*** */
        float* batch_normalization_operation_function();
};

BatchNormalization::BatchNormalization(struct tensor **tn, float **input, string l_name)
                    :Layer(**tn, **input)
{
    layer_name = l_name;
}

How can resolve this problem? How can we define constructors if the base class contains double-pointer member?

Sander De Dycker
  • 16,053
  • 1
  • 35
  • 40
  • Please provide a [mre] for demonstration. – Yunnosch Feb 19 '20 at 07:31
  • 2
    Have you tried just passing in tn, input? – Omid CompSCI Feb 19 '20 at 07:37
  • Looks like your use of pointers is plain wrong. What the `Layer()` constructor is doing is very troubling. It is not altering `tensor_node` and `tensor_input_activation`, if you believe that's what it is doing… – ypnos Feb 19 '20 at 07:43
  • struct is not a typename, but a keyword – mfnx Feb 19 '20 at 07:43
  • The type of `tn` is `struct tensor**` ; the type of `**tn` is `struct tensor`. Which does the `Layer` constructor need ? Which one are you passing ? – Sander De Dycker Feb 19 '20 at 07:43
  • [What does “dereferencing” a pointer mean?](https://stackoverflow.com/questions/4955198/what-does-dereferencing-a-pointer-mean) – Sander De Dycker Feb 19 '20 at 07:46
  • 1
    In the initialiser list within `BatchNormalization::BatchNormalization(struct tensor **tn, float **input, string l_name) :Layer(**tn, **input)` you need to remove excess asterisks in the initialiser of the base class, to give `BatchNormalization::BatchNormalization(struct tensor **tn, float **input, string l_name) :Layer(tn, input)`. Voting to close, since this is essentially a typo (albeit one resulting from not properly understanding what pointer dereferencing does). – Peter Feb 19 '20 at 08:43

1 Answers1

1

You pass Layer(tn, input). But before you do that you should fix Layer::Layer to stop dereferencing invalid pointers.

Layer::Layer(tensor **tn, float **input)
   : tensor_node(tn), tensor_input_activation(input)
{}

BatchNormalization::BatchNormalization(tensor **tn, float **input, string l_name)
   : Layer(tn, input), layer_name(l_name)
{}
Caleth
  • 52,200
  • 2
  • 44
  • 75