I'm trying to sum all the elements of a vector of vectors of vectors ... of integers: something like a std::vector<std::vector<std::vector<std::vector<int>>>>
where there's no need to every layer have the same size.
I would like to accomplish it using template, so I did it:
namespace nn
{
template < class T >
int sumAllElements(std::vector<T> v)
{
int size = v.size();
int output = 0;
for ( int i = 0 ; i < size ; i++ )
{
//should call the function below
output += sumAllElements( v[ i ] ); //or this function, depending in
//which "layer" we are
}
return output;
}
int sumAllElements(std::vector<int> v)
{
int size = v.size();
int output = 0;
for ( int i = 0 ; i < size ; i++ )
{
output += v[ i ]; //we've reached the bottomest layer,
//so just sum everybory
}
return output;
}
}
BUT, this is happening:
CMakeFiles\test.dir/objects.a(main.cpp.obj): In function `main':
D:/test/main.cpp:49: undefined reference to `int nn::sumAllElements<std::vector<int, std::allocator<int> > >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\test\build.make:141: test.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:67: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:79: CMakeFiles/test.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: test] Error 2
I really don't know why...
Thanks in advance.