I created a code file to keep all my global variables and one of them is an array like this one:
global.cpp
#include <array>
array<string, 3> arr = {"value1", "value2","value3"};
I test arrays values in another code file like this:
testarrays.cpp
#include <iostream>
#include <array>
template <size_t N>
void TestingArrays(const array<string, N>& ArrT);
void ArrayTester()
{
extern array<string,3> arr;
array <string, 2> localarr = {"v1" ,"v2"};
TestingArrays(localarr);
TestingArrays(arr);
}
template <size_t N>
void TestingArrays(const array<string, N>& ArrT)
{
for (auto it = ArrT.cbegin(); it != ArrT.cend(); ++it)
{
cout << "Testing " << *it << endl;
}
}
Everything is beautiful except for one thing. I use this global array (Arr
) in many other places.
That means if I need to change the number of variables (it have 3 in this example) I need to do the same over all code files... ...crazy...
I thought to use a template like this:
testarrays.cpp
...
template <size_t N>
extern array<string,N> arr;
...
...but it didn't compiled.
Someone have a tip to solve this problem?