I have declared a vector like this for managed type.
My question is how it is possible to declare a number of elements as you do for native like this. OneVector(10) ?

If I write OneVector(10) below this will not work. Either if I write OneVector.AddRange(10).
Thanks...

public: System::Collections::Generic::List<double> OneVector;

> My question is how it is possible to declare a number of elements as you do for native like this. OneVector(10) ?
It isn't possible, but you can get close by using one of the overloads for the List<> class that expects an IEnumerable<T> object:

using namespace System;
using namespace System::Collections::Generic;

#include <iostream>

int main()
{
  array<int>^ src = {1, 2, 3, 4, 5, 6};
  List<int>^ numbers = gcnew List<int>((IEnumerable<int>^)src);

  for each (int value in numbers)
    std::cout << value << '\n';
}

The cast is a necessary evil, and Edward would guess that's why AddRange didn't work because it's the same thing in a different place:

using namespace System;
using namespace System::Collections::Generic;

#include <iostream>

int main()
{
  array<int>^ src = {1, 2, 3, 4, 5, 6};
  List<int>^ numbers = gcnew List<int>();

  numbers->AddRange((IEnumerable<int>^)src);

  for each (int value in numbers)
    std::cout << value << '\n';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.