Reputation: 125
I have been cracking my head over this one. I've searched all over and all I seem to find are issues with the same error messages but involving either building complete iphone apps or dealing with header files, all sorts of stuff.
I was just writing a simple C++ program, no header files except the typical iostream, stdlib.h and time.h. This is for a very simple college assignment, but I can't keep working because Xcode gives me this error that has nothing to do with the actual code (based on what I've read). I haven't messed with anything other than the actual .cpp file, I don't even know how I could've messed this up. I've done multiple assignments the same way and have never run into this issue before.
Current code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
//functions
void funcion1(int matriz, int renglones, int columnas);
void funcion2(int matriz, int renglones, int columnas);
//variables
int renglones=8;
int columnas=8;
int ** matriz = new int*[renglones];
int main()
{
//reservar columnas
for (int i=0; i < renglones; i++)
{
matriz[i] = new int[columnas];
}
srand(time(NULL));
funcion1(**matriz, renglones, columnas);
funcion2(**matriz, renglones, columnas);
}
void funcion1(int **matriz, int renglones, int columnas)
{
for (int y = 0; y <= renglones; y++)
{
for (int x = 0; x <= columnas; x++)
{
matriz[y][x] = rand() % 10;
}
}
}
void funcion2(int **matriz, int renglones, int columnas)
{
for (int y = 0; y <= renglones; y++)
{
for (int x = 0; x <= columnas; x++)
{
cout << matriz[y][x] << " ";
}
cout << "\n";
}
}
Screenshot of error screen
EDIT: Fixed code below.
void funcion1(int **matriz, int renglones, int columnas)
{
for (int y = 0; y < renglones; y++)
{
for (int x = 0; x < columnas; x++)
{
matriz[y][x] = rand() % 10;
}
}
}
void funcion2(int **matriz, int renglones, int columnas)
{
for (int y = 0; y < renglones; y++)
{
for (int x = 0; x < columnas; x++)
{
cout << matriz[y][x] << " ";
}
cout << "\n";
}
}
Upvotes: 4
Views: 31859
Reputation: 35440
You failed to supply the funcion1(int, int, int)
and funcion2(int, int, int)
functions to the linker. You're calling them in your main() program, but the linker can't find it.
And no, this does not call your funcion1(int**, int, int)
function:
funcion1(**matriz, renglones, columnas);
You are dereferencing the int**
on two levels, thus yielding an int
. Same thing with your call to funcion2
.
To call the funcion1(**matriz, renglones, columnas)
function:
funcion1(matriz, renglones, columnas);
Same thing with funcion2(int **, int, int);
funcion2(matriz, renglones, columnas);
Upvotes: 5