undefined reference to "function name"

Everything seems to be in order and I know my code still has mistakes. I'm just trying to get it to compile and it won't allow it. I've narrowed it down to when I call the functions in main but beyond that I have no clue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstring>
using namespace std;

void getSize(int num);
void getSpace(int num, int ptr);
void inputData();
void printData();
void destroy();

const int BIG_NUMBER = 100;

int main()
{
int numberStrings = 0;
int stringAddress[BIG_NUMBER];

getSize(numberStrings);

getSpace(numberStrings, stringAddress[BIG_NUMBER]);

return 0;
}


void getSize(int &numStr)
{
   cout << "How many strings do you want to create?";
   cin >> numStr;
}



void getSpace(int numStr,int *ptr[BIG_NUMBER])
{

   
   for(int i=0; i<numStr; i++)
        {
       ptr[i] = new int;
       
       cout << ptr[i] << " ";
        }

}
You declare functions getSize and getSpace with one signature, then later define them with completely different signatures. Thus, you have two overloads of each, and each function only has one of the overloads defined.

Change your forward declarations on lines 5 and 6 to match those on 26 and 34.
Alright my forward declarations are all fixed.
Now it is telling me "invalid conversion from 'int' to 'int**' on line 21

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#include <iostream>
#include <cstring>
using namespace std;

const int BIG_NUMBER = 100;

void getSize(int &numStr);
void getSpace(int &numStr, int *ptr[BIG_NUMBER]);
void inputData();
void printData();
void destroy();

int main()
{
int numberStrings = 0;
int stringAddress[BIG_NUMBER];

getSize(numberStrings);

getSpace(numberStrings, stringAddress[BIG_NUMBER]);

return 0;
}


void getSize(int &numStr)
{
   cout << "How many strings do you want to create?";
   cin >> numStr;
}



void getSpace(int numStr,int *ptr[BIG_NUMBER])
{

   
   for(int i=0; i<numStr; i++)
        {
       ptr[i] = new int;
       
       cout << ptr[i] << " ";
        }

}


either use int *ptr or int ptr[BIG_NUMBER] in your function params and then pass it as stringAddress otherwise I guess if you want to do it now as a pointer to array then &stringAddress
Last edited on
int *ptr[BIG_NUMBER]

This describes an array of pointers to int. What you are attempting to pass as a parameter is an array of int. You may not convert one to the other (such a conversion would be nonsensical) as your compiler is helpfully letting you know.
Topic archived. No new replies allowed.