the_martian the_martian - 8 months ago 53
C++ Question

Prototype error from c++ header

I'm getting a prototype error: hanning.

cpp:26:1: error: prototype for 'int hanning::randomArray(int*, int*, int*)' does not match any in class 'hanning'
hanning::randomArray(int *length, int *lowValue, int *highValue) {
^~~~~~~


However, I'm not sure what I've done wrong. Here is a sample of the header and class file in question:

#ifndef HANNING_HPP
#define HANNING_HPP

class hanning {
public:
int *randomArray(int *length, int *lowValue, int *highValue); //Problem 1

private:

};

#endif /* HANNING_HPP */


and now the class:

#include "hanning.hpp"

#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <time.h>


using namespace std;

// Problem 1: Random Number array
//Fills a dynamically allocated array with random numbers in a low to high range
hanning::randomArray(int *length, int *lowValue, int *highValue) {
*length = (rand() % 25) + 25;
*lowValue = -1 * (rand() % 5 + 5);
*highValue = (rand() % 5) + 5;

int *arr = new int[*length];

for (int i = 0; i < *length; i++) {
arr[i] = rand() % (*highValue - *lowValue + 1) + *lowValue;
}

return arr;
}


I don't know why I'm having this problem. I'm using netbeans 8.2

Answer Source

You forgot the return type int * in your function definition:

int *hanning::randomArray(int *length, int *lowValue, int *highValue) {
    ...
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download