Cannot convert `double' to `double (*)[5]' for argument `1' to `double facelines(double (*)[5], double (*)[5])'

I don't understand why I am getting this error.

56 Z:\Win7Files\Documents\DevC++\IM.cpp cannot convert `double' to `double (*)[5]' for argument `1' to `double facelines(double (*)[5], double (*)[5])'

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

#include <iostream>  /* Allows ouputes to the screen */
#include <fstream>  /* Allows files to be input and ouput */
#include <string>   /* Allows file strings to be used */
#include <iomanip>
#include <math.h>

 using namespace std; /* Allows certain parts of the code to be written without the prefix stating it is from the standard library */

double facelines(double array1[25][5], double array2[25][5]);

 int main()  /* This signals the start of the main function */
 {
     
     ifstream facedata; 
     ofstream names, xcoor, ycoor;
     int a;
     double xcor[25][5], ycor[25][5], distancearray[25][10];
     string name[25];

	facedata.open("facedata.txt");
	names.open("names.txt");
	xcoor.open("xcoor.txt");
	ycoor.open("ycoor.txt");


	facedata >> a; 

     for (int c=0; c<a; c++)
     {
         
         for (int b=1; b<=2; b++)
         {
         facedata >> name[c];
         names << name[c];
         cout << name[c] << endl;
         }
         cout << endl;
         
         
         for (int w=1; w<=5; w++)
         {
             facedata >> xcor[c][w]; 
             xcoor << xcor[c][w];

         }


         for (int p=1; p<=5; p++)
         {
             facedata >> ycor[c][p];
             ycoor << ycor[c][p];

         }
         }
         
         distancearray[25][10]=facelines(xcor[25][5], ycor[25][5]);   /* This is where the error occurs */


     facedata.close();
     names.close();;
     xcoor.close();
     ycoor.close();
     

     
     for (int row=0; row<=25; row++)
     {
         for (int col=0; col<=25; col++)
         {
             cout << distancearray[row][col];
             }
             cout << endl;
             }
     
     
     string infile;
     ifstream suspect;
     double xsuspect[1][5], ysuspect[1][5];
     
     cout << "What is the name of the test file?  ";
     cin >> infile;
     
     suspect.open(infile.c_str());
     if(suspect.fail())
     {
                    cerr << "Error: File not found."<< endl;
                    system("pause");
                    exit(1);
     }
     
     
     for (int c=0; c<=1; c++)
     {
              for (int w=1; w<=5; w++)
         {
             suspect >> xsuspect[c][w];
         }


         for (int p=1; p<=5; p++)
         {
             suspect >> ysuspect[c][p];
         }
         }


     system("pause");
     return(0);
 } 
 
 
double facelines(double array1[25][5], double array2[25][5])
 {
      double distance1a2, distance1a3, distance1a4, distance1a5, distance2a3, distance2a4, distance2a5, distance3a4, distance3a5, distance4a5, distancearray[25][10];
      
          for (int c=0; c<=25; c++)
          {

              distance1a2=sqrt(pow((array1[c][0]-array1[c][1]),2)+pow((array2[c][0]-array2[c][1]),2));
 
              distance1a3=sqrt(pow((array1[c][0]-array1[c][2]),2)+pow((array2[c][0]-array2[c][2]),2));
  
              distance1a4=sqrt(pow((array1[c][0]-array1[c][3]),2)+pow((array2[c][0]-array2[c][3]),2));
  
              distance1a5=sqrt(pow((array1[c][0]-array1[c][4]),2)+pow((array2[c][0]-array2[c][4]),2));
    
              distance2a3=sqrt(pow((array1[c][1]-array1[c][2]),2)+pow((array2[c][1]-array2[c][2]),2));

              distance2a4=sqrt(pow((array1[c][1]-array1[c][3]),2)+pow((array2[c][1]-array2[c][3]),2));
  
              distance2a5=sqrt(pow((array1[c][1]-array1[c][4]),2)+pow((array2[c][1]-array2[c][4]),2));

              distance3a4=sqrt(pow((array1[c][2]-array1[c][3]),2)+pow((array2[c][2]-array2[c][3]),2));

              distance3a5=sqrt(pow((array1[c][2]-array1[c][4]),2)+pow((array2[c][2]-array2[c][4]),2));

              distance4a5=sqrt(pow((array1[c][3]-array1[c][4]),2)+pow((array2[c][3]-array2[c][4]),2));
              
              distancearray[c][10]=(distance1a2, distance1a3, distance1a4, distance1a5, distance2a3, distance2a4, distance2a5, distance3a4, distance3a5, distance4a5);
              }
              
              return(distancearray[25][10]);
              
}

distancearray[25][10]=facelines(xcor[25][5], ycor[25][5]); /* This is where the error occurs */

xcor[25][5] is an out of bounds element of your array.

Just as xcor[0][0] accesses a single element, so does xcor[25][5]. It does not suddenly have a different meaning when you put the size of the array in the brackets -- the only thing it means is that you are going out of bounds.


If you want to pass the array to the function, pass the array (as in, use the array name), not a single element:

 
facelines(xcor, ycor);


Of course... distancearray[25][10] is also out of bounds and you absolutely should not be assigning it.

If you are trying to return a full array and assign a full array -- you can't. C++ doesn't allow it.

Instead, you can use a container class like a vector... then you can assign and return them.
Doesn't saying array[25][5] just state the size of the array though? Like it has 25 rows and 5 columns
Doesn't saying array[25][5] just state the size of the array though? Like it has 25 rows and 5 columns


No.

The number in brackets is the size only when you create it. Everywhere else, it is used an index to fetch a specific element from the array.

1
2
3
4
int foo[5];  // <- here we are creating the array.  So the '5' is the size.

cout << foo[5]; // <- we are not creating it (it was already created), so this is attempting to
   //  access index 5, which is out of bounds. 
Topic archived. No new replies allowed.