-2

I have a class which holds a 2D array as a member.

int neighbourhood[30][5];

And a class member function that needs to copy a incoming array;

template <typename TwoDArray>
void set_neighbourhood(TwoDArray& nbh)
{
    neighbourhood = nbh;
}

As evident from the code, a template type is in place. Why use templates? Well passing 2D arrays seems to easy and clean according to the answer here

But I am getting a L-value error and seems that this is not the right syntax to copy the array.

Definitely I am missing something.

Wajih
  • 714
  • 3
  • 10
  • 29

1 Answers1

1

If you do not have it yet you may need to write a method for the = operator. Below is an example of one I wrote recently.

for example in your constructor you'll need to write

SingleLink& operator=(SingleLink);

then outside constructor

template<typename K, typename V>
SingleLink<K,V>& SingleLink<K,V>::operator=(SingleLink sl){
    swap(head_, sl.head_);
    swap(tail_, sl.tail_);
    return *this;
}

In my case head_ and tail_ are some of my class members. Also I took in two template types while it seems you only have to worry about one.

Jake Sak
  • 40
  • 6