0

I'm trying to pass an array to a library (written in c++) but the error:

undefined reference to `MyLib::arrayTest(int*)'
collect2: error: ld returned 1 exit status
Error compiling.

Is being produced.

My Code Is As Follows:

Testing.ino:

MyLib test = MyLib(5,4,6);

void setup(){
    int arr[10];

    test.arrayTest(arr);

    Serial.println(arr[0]);
}

MyLib.h:

class MyLib {
    public:
        MyLib(int x, int y, int z);

        void arrayTest(int* n);

MyLib.cpp:

void arrayTest(int* n){
    n[0] = 15;
}

Any help is greatly appreciated :)

2
  • class MyLib is incomplete.
    – Majenko
    Commented Jul 3, 2016 at 20:40
  • I have that correct in the code I just made a mistake when posting the question, sorry about that
    – StackNinja
    Commented Jul 3, 2016 at 20:41

1 Answer 1

0

This function:

void arrayTest(int* n){
    n[0] = 15;
}

is lacking the class qualifier:

void MyLib::arrayTest(int* n){
    n[0] = 15;
}
1
  • @StackNinja Easily done. I have done it myself numerous times.
    – Majenko
    Commented Jul 3, 2016 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.