简体   繁体   中英

Pointer to Error: Linking Error in C++

Following is my code...

    #include"PointerToArray.h"
#include <iostream>
using namespace std;
void display(const int (*displayM)[10],int resultRow,int resultColumn)
{

for(int i=0;i<resultRow;i++)
{
    for(int j=0;j<resultColumn;j++)
    {
         cout<<displayM[i][j];
    }
}

}

void read()
{
 int (*matrixA)[10],(*matrixB)[10];
 int row1,col1,row2,col2;
cout<<"Enter the number of rows and colums for Matrix1";
cin>>row1>>col1;
matrixA=new int[row1][10];
cout<<"Enter elements"<<endl;
for(int i=0;i<row1;i++)
{
    for(int j=0;j<col1;j++)
    {
         cin>>matrixA[i][j];
    }
}

cout<<"Enter the number of rows and colums for Matrix2";
cin>>row2>>col2;
matrixB=new int[row2][10];
cout<<"Enter elements"<<endl;
for(int i=0;i<row2;i++)
{
    for(int j=0;j<col2;j++)
    {
         cin>>matrixB[i][j];
    }
}

display(matrixA,row1,col1);



}

I am getting error as

1:1>C:\\Progs\\PointerToArray\\Debug\\PointerToArray.exe : fatal error LNK1120: 1 unresolved externals 2:1>PointerToArray.obj : error LNK2019: unresolved external symbol "void __cdecl display(int (*)[10],int,int)" (?display@@YAXPAY09HHH@Z) referenced in function "void __cdecl read(void)" (?read@@YAXXZ)

Can any one suggest the way?

The display function signature in your .c file is different from your error message in that there is no 'const' there. Can you check that in PointerToArray.h the function declaration (prototype) does not have

void display(int (*displayM)[10],int resultRow,int resultColumn)

but

void display(const int (*displayM)[10],int resultRow,int resultColumn)

instead?

If it does you can resolve it by changing either one to match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM