// testing1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <iostream>
#include<conio.h>
using namespace std;
struct Data_point {
double x;
double y;
};
void PlotThis(unsigned int n )
{
Data_point graph[n]; //shows error here
//do something else, dont worry about that
}
int main ()
{
unsigned int nSamples;
cout << "Please enter nSamples: ";
cin >> nSamples;
PlotThis(nSamples);
return 0;
}
This shows error when compiling:
Error 1 error C2057: expected constant expression testing1.cpp 23
Error 2 error C2466: cannot allocate an array of constant size 0 testing1.cpp 23
Error 3 error C2133: 'graph' : unknown size testing1.cpp 23
Line 23 is Data_point graph[n]; //shows error here
It is showing unknown size even though I am passing it the value from main(). It is asking for the value (the size of graph i.e n) at the compile time. Does that mean array size allocation takes place at compile time? How to solve this