pandoragami
pandoragami

Reputation: 5575

error: no match for 'operator=' . Trying to inherit from base class and initialize from base class?

I'm trying to declare a base class called BASE and I'm having trouble using the inherited types A and B inside of the BASE class. I'm getting the error

|In member function 'NODE& NODE::operator=(const NODE&)':|
16|warning: no return statement in function returning non-void|
In member function 'void BASE<T, SIZE>::init_A(int) [with T = NODE, unsigned int SIZE = 2u]':|
96|instantiated from here|
39|error: no match for 'operator=' in 'A<NODE, 2u>::DATA[index] = a'|
13|note: candidates are: NODE& NODE::operator=(const NODE&)|


#include <iostream>

class NODE
{
        private:

        public:

        NODE(){}
        ~NODE(){}

};

template <class T, size_t SIZE>
class A;
template <class T, size_t SIZE>

class BASE
{
    protected:

        static T DATA[SIZE];

    public:

        BASE()
        {

        }
        ~BASE(){}
        void init_A(int index)
        {                       
            A<T,SIZE>::DATA[index] = T();            
        }        
};
template <class T, size_t SIZE>
class A : public BASE<T,SIZE>
{
     protected:         

    public:


        A(){}
        ~A(){}

};

template <class T, size_t SIZE>
T BASE<T,SIZE>::DATA[SIZE] = {};
int main()
{
    BASE<NODE,2> base;

    base.init_A(0);    

    return 0;
}

Upvotes: 0

Views: 931

Answers (1)

doctorlove
doctorlove

Reputation: 19272

I can make it compile, but it might not do what you want. The first problem is you assignment operator promises to return something and doesn't:

NODE& NODE::operator=(const NODE&)
{

}

Try this

NODE& NODE::operator=(const NODE&)
{
    return *this;
}

The second problem is

A<T,SIZE> a;
A<T,SIZE>::DATA[index] = a;

The DATA is an array of T, not an A<T,SIZE>. Try this

A<T,SIZE>::DATA[index] = T();

Finally you need to declare your statics somewhere.
Finally you need to define your statics somewhere.See here

Upvotes: 2

Related Questions