0

I'm trying to pass to a constructor class a 2d array

std::array<std::array<int, dimension>, dimension>

I do some search, and i tried to use the template.. But doesn't work

But, my code produce the following error :

Undefined symbols for architecture x86_64:
 "state::state<std::__1::array<int, 4ul>, 4ul>(int, std::__1::array<std::__1::array<int, 4ul>, 4ul> const&)", referenced 
from:
  _main in main-d76757.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The code of the main :

int main () {

  const int dimension = 4;
  std::array<int, dimension> j;
  std::array<std::array<int, dimension>, dimension> array;
  array[0][0] = 0;
  array[0][1] = 7;
  array[0][2] = 4;
  array[1][0] = 3;
  array[1][1] = 8;
  array[1][2] = 6;
  array[2][0] = 1;
  array[2][1] = 5;
  array[2][2] = 2;



  state t = state(dimension, array);

}

And here the code of the constructor :

template<typename T, size_t N>
state::state(const int dim, std::array<T, N> const &array) : dimension(-1)
{
// DO STUFF

}
Pusheen_the_dev
  • 2,077
  • 4
  • 17
  • 33
  • Because I want to copy the 2d array in an attribute member of the class. However, a 1d array produce the same error... – Pusheen_the_dev Apr 18 '15 at 19:07
  • [Might be this](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file). Hard to tell without an [MCVE](http://stackoverflow.com/help/mc.ve) – chris Apr 18 '15 at 19:07
  • In fact, the 2d array need to be the key of a std::map. If I could use a 2d int directly, i would.. – Pusheen_the_dev Apr 18 '15 at 19:12
  • The constructor apperas to take 1Darray but you are passing two D or am I missing something? – itachi Apr 18 '15 at 19:14
  • @itachi, It takes a 1D array of any type, including an array. – chris Apr 18 '15 at 19:15

0 Answers0