array function

Namal via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 31 04:41:03 PDT 2015


On Monday, 31 August 2015 at 11:27:20 UTC, Rikki Cattermole wrote:

> You cannot define static arrays using runtime information.
> You must use dynamic arrays.
>
> int[] foo(int N) {
> 	int[] v;
> 	v.length = N;
> 	// do something with it
> 	int[] 2;
> 	return s;
> }
>
>
> Of course you can pass it in via a template argument. But this 
> of course does not work at runtime like you are wanting.


Hmm, this has never been a problem for me in C++

#include <vector>


std::vector<int> foo(int N){

	std::vector<int> V(N);
	int some_array[N];

	std::vector<int> other_V;

	return other_V;
	
}

int main(){

std::vector<int> V = foo(12);


}

compiles



More information about the Digitalmars-d-learn mailing list