About the error: expected initializer before ??token problem

I wrote the code for the pointer as a return type, but why my function cannot be use. This is my code.
#include<iostream>
#include<stdlib.h>
#include<cstddef>
#define nullptr NULL

using namespace std;

int main(){
int *test;
int input;
int getRandomNumbers *test = new getRandomNumbers(input);
cin >> input;
return 0;
}

int *getRandomNumbers(int num){

int *arr = nullptr; //Array to hold the numbers

//Return a null pointer if num is zero or negative.
if(num <= 0)
return nullptr;

//Dynamically allocate the array
arr = new int[num];

//Seed the random number generator by passing
//the return value of time(0) to srand
srand( time(0));


//Populate the array with random numbers.
for(int count = 0; count < num; count++)
arr[count] = rand();

//Return a pointer to the array.
return arr;
}
1) When posting code, please use code tags to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) If you have error messages, tell us what they are. Show us the whole error message, including the line number. Why would you decide to withhold information from us?

3) What are you trying to achieve by using "new" in the line:

int getRandomNumbers *test = new getRandomNumbers(input);

getRandomNumbers is a function, not a type of object.
1. add a prototype declaration before the start of main()
int *getRandomNumbers(int num);

2. Change
 
    int getRandomNumbers *test = new getRandomNumbers(input);
to
 
    int *test = getRandomNumbers(input);


3. Move the cin statement so that the variable input actually has a value before you try to use it in the function call.
Topic archived. No new replies allowed.