title: Can't have an array as a return type in C++? Alternatives?
body: <p>I'm learning C++ and it seems like it is impossible to have an array as a return type. Is this true? </p>
  
  <pre><code>int foo(){}
  </code></pre>
  
  <p>works fine but</p>
  
  <pre><code>int[] foo(){}
  </code></pre>
  
  <p>does not. What is the commonly accepted work around to this? </p>
  
  <p>I'm currently working on a project that utilizes both C# and C++. I have a C# file that access some DLL code with:</p>
  
  <pre><code>[DllImport("Test.dll")]
  public static extern byte[,] getBytes(
      [In] string filePath,
      [In] string dataGroup); 
  </code></pre>
  
  <p>My header file has:</p>
  
  <pre><code>TEST_DLL BYTE[][] getBytes(std::string filePath, std::string dataGroup);
  /* This throws an error since I can't use an array as a return type. */
  </code></pre>
  
  <p>and my implementation inside the .cpp file is:</p>
  
  <pre><code>TEST_DLL BYTE[][] getBytes(std::string filePath, std::string dataGroup)
  {
      printf("getBytes entered."
  
      /* More code here...*/
  }
  
  /* This also throws an error due to the array use. */
  </code></pre>
  
  <p>Basically, I'm trying to return a 2D byte array from my DLL code <strong>without needing to convert anything on the C# side, i.e., all code execution related to getBytes should occur in the C++ code.</strong> </p>
  
  <p>I have a working example of this that does not use an array but rather a void*, which from my understanding is a pointer to the array I'm returning. I then have a C# function that uses an IntPtr and Marshal.Copy to get the byte array. I'm trying to determine the overhead difference between the two methods. I would imagine that it would be much faster to return a 2D byte array directly from the C++ code instead of using the additional C# conversion code (the datasets I'm using are huge - some over 500GB so every little bit of optimization counts). </p>
  
  <p>Basically, how can I retrieve a 2D byte array purely from my C++ code without having to convert it in C#?</p>