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();
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.