Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.67/6: Рейтинг темы: голосов - 6, средняя оценка - 4.67
0 / 0 / 0
Регистрация: 09.04.2015
Сообщений: 8
1

Много ошибок illegal use of floating point

19.05.2015, 17:16. Показов 1177. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте! Столкнулся с такой ошибкой, в упор не понимаю, в чем дело. Прекрасно понимаю, что Points[poly[N].point1] имеет тип float, а poly[N].point1 и т.д. тип int. Но почему ошибка возникает не понимаю, уже весь код перелопатил и результат такой же. Кто что думает?
C++
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
struct Point
 
{
 
    float x;
 
    float y;
 
    float z;
 
 
 
};
 
 
struct Poly
{
 
    float point1, point2, point3,point4;
    float Normal[3];
        int s;
};
 
 void DoPointVector(int i, int j, float PointVector[3])
    {PointVector[X]=float(j)-320;
    PointVector[Y]=float(i)-240;
    PointVector[Z]=float(points[i][j]);
    }
 
class surface
{
private:
    int N;
    int PointN;
     float **Points;
 
public:
    Poly *poly; 
    
    surface(int inN)   
    {
        N=0;
                PointN=0;
        poly=new Poly[inN]; 
                Points=new float*[inN];
    }
 
    ~surface() {
        delete [] poly;
          }
 
          void read_file ( char * name_file,char *name_file2 )
          {
              FILE *f = fopen(name_file, "rb");
              FILE *s = fopen(name_file2, "rb");
 
              double temp;
              double shad;
              for(int x = 0; x < 480; x++)
              {
 
                  for(int y = 0; y < 640; y++)
                  {
 
                      fread(&temp,sizeof(double),1,f);
                      fread(&shad,sizeof(double),1,s);
                      points[x][y]=(int)temp;
                      S[x][y]=(int)shad;
 
                  }
              }
 
              fclose(f);
              fclose(s);
          }
 
 
        
                  void set_polygons ()
                            {
                                int x, y;
                float Point1[3],Point2[3],Point3[3],Point4[3];
                float Normal[3];
 
 
            
 
              for( x = 0; x < 480-2; x++ )              
              {
                  for( y = 0; y < 640-2; y++ )          
                  {
 
                  if ((points[x][y]>-20)&&(points[x+1][y]>-20)&&(points[x][y+1]>-20)&&(points[x+1][y+1]>-20))
                 {
 
 
 
     if ((S[x][y]==0)&&(S[x+1][y]==0)&&(S[x][y+1]==0)&&(S[x+1][y+1]==0))
         this->poly[N].s=0; else this->poly[N].s=1;
 
    if (index[x][y]==-1) {
 
     index[x][y]=PointN;
    DoPointVector(x,y,Point1);
     this->Points[PointN]=new float[3];
                       this->Points[PointN][0]= Point1[0];
                       this->Points[PointN][1]= Point1[1];
                       this->Points[PointN][2]= Point1[2];
                       this->poly[N].point1=PointN;
                       PointN++;
       }  else {this->poly[N].point1=index[x][y];}
 
       if (index[x][y+1]==-1) {
 
     index[x][y+1]=PointN;
    DoPointVector(x,y+1,Point2);
     this->Points[PointN]=new float[3];
                       this->Points[PointN][0]= Point2[0];
                       this->Points[PointN][1]= Point2[1];
                       this->Points[PointN][2]= Point2[2];
                       this->poly[N].point2=PointN;
                       PointN++;
       }  else {this->poly[N].point2=index[x][y+1];}
 
        if (index[x+1][y+1]==-1) {
 
     index[x+1][y+1]=PointN;
    DoPointVector(x+1,y+1,Point4);
     this->Points[PointN]=new float[3];
                       this->Points[PointN][0]= Point4[0];
                       this->Points[PointN][1]= Point4[1];
                       this->Points[PointN][2]= Point4[2];
                       this->poly[N].point3=PointN;
                       PointN++;
       }  else {this->poly[N].point3=index[x+1][y+1];}
            WorkOutNormal(this->Points[poly[N].point1],this->Points[poly[N].point2],this->Points[poly[N].point3],this->poly[N].Normal); // ОШИБКА ТУТ, точнее 3, как я понимаю на point 1,2,3
 
                                         N=N+1;
 
             this->poly[N].point1=index[x][y];
 
                if (index[x+1][y]==-1) {
 
     index[x+1][y]=PointN;
    DoPointVector(x+1,y,Point3);
     this->Points[PointN]=new float[3];
                       this->Points[PointN][0]= Point3[0];
                       this->Points[PointN][1]= Point3[1];
                       this->Points[PointN][2]= Point3[2];
                       this->poly[N].point2=PointN;
                       PointN++;
       }  else {this->poly[N].point2=index[x+1][y];}
 
        this->poly[N].point3=index[x+1][y+1];
 
                WorkOutNormal(this->Points[poly[N].point1],this->Points[poly[N].point2],this->Points[poly[N].point3],this->poly[N].Normal); //- ОШИБКА ТУТ, те же,что и на прошлом WorkOutNormal
 
             N=N+1;                                        }
                        }}
                            }
 
 
void MultMatrixX(float *point,float angle)
 
           {
 
             float pointold[3];
 
           pointold[0]=point[0];
           pointold[1]=point[1];
           pointold[2]=point[2];
 
float m[9]={ 1.0f,   0.0f,    0.0f,
              0.0f,         cos(angle),     sin(angle),
              0.0f,   -sin(angle),    cos(angle)
              };     
 
           point[0]=(pointold[0]*m[0] + pointold[1]*m[1] + pointold[2]*m[2]  );
           point[1]=(pointold[0]*m[3] + pointold[1]*m[4] + pointold[2]*m[5]  );
           point[2]= pointold[0]*m[6] + pointold[1]*m[7] + pointold[2]*m[8] ;
 
           }
 
           void rotate(float angle)
           {           int i;
            
                       
 
/*GLfloat m[]={ cos(angle),   0.0f,    -sin(angle),      0.0f,
              0.0f,         1.0f,     0.0f,            0.0f ,
              sin(angle),   0.0f,    cos(angle),       0.0f,
              0.0f,         0.0f,     0.0f,            1.0f
              };   */
 
 
 
     //    glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();
 
   // glMultMatrixf(m);
                  for(  i = 0; i < PointN; i++ )
                                           {
                       
                                    MultMatrixX(this->Points[i],angle);
                                            }
           }
 
    
        void draw_polygons2 ()
          {
                       int i;
 
                  for(  i = 0; i < N; i+=2 )
                  {
                    glColor3f(1.0f,0.75f,0.75f);
 
                      if( this->poly[i].s==0)
                        glColor3f(0.3f,0.3f,0.75f);
 
 
            WorkOutNormal(Points[poly[i].point1],Points[poly[i].point2],Points[poly[i].point3],Normal); //- ОШИБКА ТУТ, точнее 3, как я понимаю на point 1,2,3, в общем тоже самое, что и в прошлые разы
            glNormal3fv(Normal);
            glVertex3fv(Points[poly[i].point1]); // Так же здесь
            glVertex3fv(Points[poly[i].point2]); // Здесь
            glVertex3fv(Points[poly[i].point3]); // Здесь
 
 
         
            glVertex3fv(Points[poly[i].point1]); // Здесь
            glVertex3fv(Points[poly[i+1].point2]); // Здесь
            glVertex3fv(Points[poly[i].point3]); // Здесь
 
        }
 
 
 
 
 
 
 
    }
Не понимаю, что компилятору не нравится в конструкции Points[poly[i].point1]!
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
19.05.2015, 17:16
Ответы с готовыми решениями:

Illegal use of floating point
Подскажите, почему с++ ругается на мою функцию: float h (float a, float b) { return...

Illegal use of floating point
Подскажите в чем может быть дело: int sigmasignal=5,i,j,N=20; float vhmatrica, rsignal; double ...

Ошибка: Illegal use of floating point
В общем вот какое дело: float a,c; c=a%2; объясните, пожалуйста, почему в данном случае...

Ошибка Illegal use of floating point
Добрый вечер, прошу помочь с ошибкой &quot;Illegal use of floating point&quot; double d=0; ...

2
lss
941 / 869 / 355
Регистрация: 10.10.2012
Сообщений: 2,706
19.05.2015, 17:19 2
Цитата Сообщение от symbot Посмотреть сообщение
Не понимаю, что компилятору не нравится в конструкции Points[poly[i].point1]!
Индексы массива не могут быть float.
0
202 / 200 / 65
Регистрация: 06.10.2013
Сообщений: 552
19.05.2015, 17:22 3
poly[i].pointX у вас имеет тип float, тогда как индекс элемента должен быть строго целочисленным. Используйте явное преобразование типа или перегружайте operator[].
Правда оба этих варианта не являются хорошими - смешения целочисленной арифметики и арифметики с плавающей точкой лучше избегать любой ценой, т.к. к какому элементу надо обращаться, если в poly[i].point1 окажется значение 2.5 или -1.5?
0
19.05.2015, 17:22
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
19.05.2015, 17:22
Помогаю со студенческими работами здесь

Illegal use of floating point in function main()
#include &lt;iostream.h&gt; #include &lt;conio.h&gt; #include &lt;math.h&gt; void main() { double a, x, y...

[C++ Error] Unit1.cpp(23): E2060 Illegal use of floating point
Ошибка на 22 строке //---------------------------------------------------------------------------...

Illegal use of floating point
#include &lt;stdio.h&gt; float factorial (int); float f (float); void main() {int a; float y;...

E2060 illegal use of floating point
Задание: x=2a+6b y=sin(a*x)cos(b*x) z=2x*y-y^2 тип исходных данных: a- целое b -...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru