-1

I am creating an Arduino library which takes two constructors for a personal project of mine, but for some reason I keep getting an error which is specific to types, first let me show you how the structure goes. so here is my files:

this is the header file:

#ifndef iGA_H
#define iGA_H
 class iGA {
   public:
         getParameters(int soundA[], int soundB[], int parentId[]);
   private:
         int _soundA[];
         int _soundB[];
         int _parentId[];
 }

the cpp file:

#include <iGA.h>
iGA::getParameters(int soundA[], int soundB[], int parentId[])
{
  _soundA = soundA;
  _soundB = soundB;
  _parentId = parentId;
 }

And this is how im pretty much calling the constructor in the sketch, within the setup() function:

#include <iGA>
iGA iga;
void setup() {
  iga.getParameters(r, r1 , r2);
}

and here is the error:

In file included from /home/bargros/Dropbox/iGA__NewBild/iGA__NewBild.ino:34:0:/home/bargros/Arduino/libraries/iGA/iGA.h:10:58: error: ISO C++ forbids declaration of 'getParameters' with no type [-fpermissive]getParameters(int soundA[], int soundB[], int parentId[]);

I know the error has something to do with argument types or maybe im calling the constructor wrongly but I also tried calling it like this:

iGA iga = getParameters(etc,etc,etc);

im relatively new to c++ and im a little clueless as to what this error is telling me. Does anyone have any sort of idea of why this happens?

Bargros
  • 521
  • 6
  • 18

2 Answers2

0

I believe two issues:

Issue 1: Your function should return something right? you may want to set it as void if it just meant to assign the parameters to the private members (it is a setter and not a get in your case). Add void in the proper locations both inside the class and when you write its definition.

Issue 2: I think that you can't send an array[] as a parameter. And I assume that you already know the size. You need, instead, to send a pointer that points to the first element of the array along with the size of the whole array. Then, once you receive the parameters, for every private member, you create a new array with the size received (or just fill the private member directly) and fill the values by iterating the received array using the pointer received.

Edit: I just checked and passing int array[] should be fine. So fixing issue one will fix your problem. See here for further documentation.

Community
  • 1
  • 1
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104
0

In C++ you have to be explicit that a function doesn't return anything, which you do by saying it returns void:

getParameters(int soundA[], int soundB[], int parentId[]);

needs to be

void getParameters(int soundA[], int soundB[], int parentId[]);

and

iGA::getParameters(int soundA[], int soundB[], int parentId[])

needs to be

void iGA::getParameters(int soundA[], int soundB[], int parentId[])
kfsone
  • 23,617
  • 2
  • 42
  • 74