the_martian
the_martian

Reputation: 634

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

Upvotes: 0

Views: 42

Answers (2)

Jack
Jack

Reputation: 133577

Your definition is the following:

hanning::randomArray(int *length, int *lowValue, int *highValue) {

There is no return type as you can see, while it should be int*.

If you are wondering why the error is not related to the definition, that's because a function with no return type is assumed to return an int so it's a valid declaration per se.

Upvotes: 2

frslm
frslm

Reputation: 2978

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

int *hanning::randomArray(int *length, int *lowValue, int *highValue) {
    ...
}

Upvotes: 2

Related Questions