I have a lot of C# Code that I have to write in C++. I don't have much experience in C++.
I am using Visual Studio 2012 to build. The project is an Static Library in C++ (not in C++/CLI).
I am sorry if this has been answered already, but I just couldn't find it.
In the C# code they would initialize a lot of arrays like this:
C#
double[] myArray = {10, 20, 30, 40};
Looking at how they were using arrays, when copying the code to C++ I decided to use std::vector to replace them. I would like to be able to initialize the vectors in the same way, because in the Unit Tests they use the arrays initialisation heavily, but I can't. I think in further versions of c++, vector supports it, but not in the one I have.
(Update)To make my previous statement more clear:
This doesn't work in VS2012:
vector<double> myVector{10, 20, 30, 40};
From this question I learned to create a vector from an array, so now I have a function like this:
C++
template<typename T, size_t N>
static std::vector<T> GetVectorFromArray( const T (&array)[N] )
{
return std::vector<T>(array, array+N);
}
It works great, but now that means I have to create the array and then use my function:
C++ (I would like to avoid this, since the UnitTests have many arrays.)
double array[] = {1, 3, 5};
vector<double> myVector = ArrayUtils::GetVectorFromArray(array);
Is there a way I could make my function GetVectorFromArray receive a list of items, that I could later convert into a vector? My compiler doesn't support C++11