-1

I am to make a function that expands an array using pointers and a function. I am rather new to coding in general and I am uncertain as to why I am getting error LNK2019. I am aware that it means there is an unresolved external, but everything that I have changed on it the same error keeps popping up. Here is my code...

#include <iostream> 
#include <iomanip> 
#include <string> 
#include <cmath> 
#include <fstream> 
#include <vector> 

using namespace std;

int * newArray(int[], int);

int main()
{
    int arr[] = { 12, 21, 56, 49, 72, 18 };

    newArray(arr, 10);

    return 0;
}

int * newArray(int arr, int size)
{
    int *p;
    int arr2;
    int *amount = new int[size * 2];
    amount = &arr2;
    int i;
    p = &arr;

    for (i = 0; i<size * 2; i++)
    {
        if (i<size)
        {
            amount[i] = p[i];
        }
        else
        {
            amount[i] = 0;
        }
    }
    arr = arr2;

    return amount;
}

Normally I would rather pass a variable by reference to do this but I need to use a pointer for this, if anyone could point me in the right direction it would be much appreciated.

Cdog5100
  • 1
  • 2

2 Answers2

0

There are many errors in your code. Some of these goes like this :-

int * newArray(int arr, int size)

You are accepting an array as int. It should be

int * newArray(int* arr, int size)

Second one is

arr = arr2;

arr is int* and arr2 an int.

ravi
  • 10,994
  • 1
  • 18
  • 36
0

you are passing int arr[] while newArray function expects an int , so that the linker is looking for some function like int * newArray(int arr[], int size) but do not find it

Luca Rocchi
  • 6,272
  • 1
  • 23
  • 23