Need help passing 2d-array between classes

So i've created:
main.cpp (creates 2d-array, then makes calls on 2 functions and passes 2d-array)
functions.cpp (contains 2 functions being called)
functions.h (has prototypes of 2 functions)

main.cpp:

#include <iostream>
#include "functions.h"
using namespace std;

int main(int argc, const char * argv[])
{

char Array2D[11][10]={{ 'c', '+', '+'}, { 'f', 'a', 'n', 't', 'a', 's', 't', 'i', 'c' }, { 'g', 'a', 'n', 'g', 'n', 'a', 'm' }, { 'h', 'o', 'w' }, { 'i', 's' }, { 'l', 'o', 'v', 'e' }, { 'm', 'u', 'c', 'h' }, { 's', 't', 'y', 'l', 'e' }, { 'v', 'e', 'r', 'y' }, { 'w', 'e' }, { 'y', 'o', 'u' }};

rowNum = func::findWord(&Array2D[10], numWords, inputArray[compare]);
func::printWord(&Array2D[10], rowNum);

return 0;
}

functions.cpp:

#include "functions.h"
#include <iostream>
using namespace func;

int findWord(char Array2D[][10], int numWords, char startingLetter){
int i=0;
int row=0;
bool found=false;
while(i<numWords){
if((*Array2D)[i]==startingLetter) {
row=i;
found=true;
}
++i;
}
if(found==true)
return row;
else
return -1;
}

void printWord(char Array2D[][10], int nthWord){
std::cout << (*Array2D)[nthWord];
std::cout << " ";
}

functions.h:
namespace func {
int findWord(char (*Array2D)[10], int i, char c);
void printWord(char (*Array2D)[10], int i);
}

I left out some code because it's not relevant to my question. I essentially need to pass the 2d-array that I created in the main.cpp, and be able to use the functions I've created in functions.cpp. It compiles I believe, but doesn't run and gives me an error:

Undefined symbols for architecture x86_64:
"func::findWord(char (*) [10], int, char)", referenced from:
_main in main.o
"func::printWord(char (*) [10], int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I appreciate any help.

functions.h:
1
2
3
4
namespace func{
int findWord(char (*Array2D)[10], int i, char c);//1d character array with 10 elements
void printWord(char (*Array2D)[10], int i);//1d character array with 10 elements
}


should be:
1
2
3
4
namespace func{
int findWord(char Array2D[][10], int i, char c);
void printWord(char Array2D[][10], int i);
}

Last edited on
Topic archived. No new replies allowed.