-1

Having some trouble figuring out what this error is.

#include <iostream>

class listSolver{
    private:
        int arraySize;
        int *address;
    public:
        listSolver(int *arrayAddress, int size);
        ~listSolver();
        int forLoopSolver();
        int whileLoopSolver();
        int recursiveSolver();
        int addNumbers(int *numAddress,int num, int count);
};

listSolver::listSolver(int *arrayAddress,int size){
    arraySize = size;
    address = arrayAddress;
}

listSolver::~listSolver(){
}

int listSolver::recursiveSolver(){
    int *funcAddress = address;
    int size = arraySize;
    int solution = 0;
    return this->addNumbers(funcAddress,size,solution);
}
int addNumbers(int *numAddress,int num, int count){
    if(count == 0){
            return num+*numAddress;
    }
    else{
            count--;
            num+=*numAddress;
            numAddress++;
            return listSolver::addNumbers(numAddress,num,count);
    }
}

g++ compiler gives me

/tmp/ccuy9bHM.o: In function 'listSolver::recursiveSolver()': problem1.cpp:(.text+0x1e2): undefined reference to 'listSolver::addNumbers(int*, int, int)' collect2: error: ld returned 1 exit status

Not sure what it means. Been trying different cominations of calling the function and can't get it to work.

iksemyonov
  • 4,106
  • 1
  • 22
  • 42
user3736114
  • 458
  • 1
  • 6
  • 17
  • `int listSolver::addNumbers(int *numAddress,int num, int count){` – πάντα ῥεῖ Oct 22 '16 at 20:49
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – πάντα ῥεῖ Oct 22 '16 at 20:50

1 Answers1

1
int ListSolver::addNumbers(int *numAddress,int num, int count){
    ^^^^^^^^^^^^

Need the class name with the scope operator ("four dots" as we call it here for ages - TY panta rhei for the spot) to define a member function outside a class body. The way it is, you've defined a global function int addNames(/* ... */) that compiles successfully per se, but since you are trying to call the said member function, at link time, an error occurs.

iksemyonov
  • 4,106
  • 1
  • 22
  • 42