Форум программистов, компьютерный форум CyberForum.ru

error C2440 при конвертации. Кусок кода работал в другой программе - C++

Восстановить пароль Регистрация
 
Рейтинг: Рейтинг темы: голосов - 13, средняя оценка - 4.77
OffyGhost
 Аватар для OffyGhost
7 / 7 / 1
Регистрация: 04.03.2010
Сообщений: 107
17.05.2011, 18:00     error C2440 при конвертации. Кусок кода работал в другой программе #1
сама программа под WinAPI, но появилось куча ошибок, связанных с error C2440
в изначальной программе кусок кода успешно компилился

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
// lab7_server.cpp : Defines the entry point for the console application.
//
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <iostream>
#include "hello.h"
using namespace std;
void determinant(float **matrix, int n);
 
void main()
{
    setlocale(LC_ALL, "Russian");
    char buffer[8];
    int N;
    int remove_string,remove_column;
RPC_STATUS status;
const char* pszProtocolSequence = "ncacn_np";
const char* pszSecurity = NULL; /*Security not implemented */
const char* pszEndpoint = "\\pipe\\he";
const int cMinCalls = 1;
const int cMaxCalls = 20;
const int fDontWait = FALSE;
status = RpcServerUseProtseqEp(pszProtocolSequence, cMaxCalls, pszEndpoint, pszSecurity);
if (status) exit(status);
status = RpcServerRegisterIf(hello_v1_0_s_ifspec, NULL, NULL);
if (status) exit(status);
status = RpcServerListen(cMinCalls, cMaxCalls, fDontWait);
if (status) exit(status);
} 
 
void HelloProc(int * N, char * buffer, int * remove_string, int remove_column)
{   
 
    N=atoi(buffer);
    cout << "Размер пересылаемой квадратной матрицы= " << N << endl;
 
    int **matrix_transfered = new int*[N];
    for (size_t i = 0; i < N; ++i) 
    {
        matrix_transfered[i] = new int[N];
    }
    for (size_t i = 0; i < N; ++i) 
    {
        for (size_t j = 0; j < N; ++j)
        {   
            matrix_transfered[i][j]=atoi(buffer);
        }
    }
    
    cout << "\nИзначальная матрица... \n";
    for (size_t i = 0; i < N; ++i) 
    {
        for (size_t j = 0; j < N; ++j) 
        {
            cout << matrix_transfered[i][j] << "  ";
        }
        cout << endl << endl;
    }
 
    remove_string=atoi(buffer);
    cout << "Вычеркиваем строчку " << remove_string << endl;
 
    remove_column=atoi(buffer);
    cout << "Вычеркиваем столбец " << remove_column << endl;
 
    float **matrix2 = new float*[N - 1];
    for (size_t i = 0; i < N - 1; ++i) 
    {
        matrix2[i] = new float[N - 1];
    }
 
    {
        for (size_t i = 0, i2 = 0; i < N; ++i) 
        {   
           for(size_t j = 0, j2 = 0; j < N; ++j)
            {
             if (i != (remove_string - 1) && j != (remove_column - 1))
                {
                    matrix2[i2][j2++] = matrix_transfered[i][j];
                }
           }
            if (i != (remove_string - 1)) ++i2;
        }
    cout << "\nПреобразованная матрица... \n";
    for (size_t i = 0; i < N - 1; ++i) 
    {
        for (size_t j = 0; j < N - 1; ++j)
        {
            cout << matrix2[i][j] << "  ";
        }
    cout << endl << endl;
    }
        determinant(matrix2, N-1);
    }
 
    for(size_t i = 0; i < N; i++)
        delete []matrix_transfered[i];
    delete []matrix_transfered;
    for(size_t i = 0; i < N - 1; i++)
        delete []matrix2[i];
    delete []matrix2;
    system("PAUSE");
}
 
void determinant(float **matrix, int n) 
{
 
    float **a = new float*[n + 1];
    for (size_t i = 0; i < n + 1; ++i) 
    {
        a[i] = new float[n + 1];
    }
    for (size_t i = 0; i < n; ++i) 
    {
        for (size_t j = 0; j < n; ++j)
            a[i][j] = matrix[i][j];
    }
 
    int p = 0;
    int t,i,j,k = 0;
    float kst = 0;
    for (i=0; i<n-1; i++)
    {
        t=1;
        while(a[i][i]==0)
        {
            for(j=0; j<n; j++)
            {
                a[i][j]=kst;
                a[i][j]=a[i+t][j];
                a[i+t][j]=kst;
            }
                p++;
                t++;
        }
        for (k=i+1; k<n; k++)
        {
            kst=a[k][i]/(float)a[i][i];
            for(j=0; j<n; j++)
            a[k][j]-=a[i][j]*kst;
        }
    }
 
    kst=pow(-1.,p);
    for(i=0; i<n; i++)
        kst*=a[i][i];
    cout << "Определитель = " << kst << endl;
         for(size_t i = 0; i < n + 1; i++)
                delete []a[i];
        delete []a;
}   
 
 
 
void Shutdown(void)
{
RPC_STATUS status;
printf("Вызываем RpcMgmtStopServerListening\n");
status = RpcMgmtStopServerListening(NULL);
printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
if (status)
{
exit(status);
}
printf("Вызываем RpcServerUnregisterIf\n");
status = RpcServerUnregisterIf(NULL, NULL, FALSE);
printf("RpcServerUnregisterIf возвратила 0x%x\n", status);
if (status)
{
exit(status);
}
}
void __RPC_FAR* __RPC_USER midl_user_allocate(size_t len)
{
return(malloc(len));
}
void __RPC_USER midl_user_free(void __RPC_FAR* ptr)
{
free(ptr);
}


1>------ Build started: Project: lab7_server2, Configuration: Release Win32 ------
1>Compiling...
1>server.cpp
1>.\server.cpp(25) : error C2664: 'RpcServerUseProtseqEpA' : cannot convert parameter 1 from 'const char *' to 'RPC_CSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\server.cpp(36) : error C2440: '=' : cannot convert from 'int' to 'int *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>.\server.cpp(39) : error C2440: 'initializing' : cannot convert from 'int *' to 'unsigned int'
1> There is no context in which this conversion is possible
1>.\server.cpp(40) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(40) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(42) : error C2440: 'initializing' : cannot convert from 'int *' to 'unsigned int'
1> There is no context in which this conversion is possible
1>.\server.cpp(44) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(44) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(46) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(46) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(53) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(53) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(55) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(55) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(62) : error C2440: '=' : cannot convert from 'int' to 'int *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>.\server.cpp(68) : error C2440: 'initializing' : cannot convert from 'int *' to 'unsigned int'
1> There is no context in which this conversion is possible
1>.\server.cpp(69) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(69) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(71) : error C2440: 'initializing' : cannot convert from 'int *' to 'unsigned int'
1> There is no context in which this conversion is possible
1>.\server.cpp(75) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(75) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(77) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(77) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(79) : error C2446: '!=' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(79) : error C2040: '!=' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(81) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>.\server.cpp(84) : error C2446: '!=' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(84) : error C2040: '!=' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(87) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(87) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(89) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(89) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(95) : error C2664: 'determinant' : cannot convert parameter 2 from 'int *' to 'int'
1> There is no context in which this conversion is possible
1>.\server.cpp(98) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(98) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(101) : error C2446: '<' : no conversion from 'int *' to 'size_t'
1> There is no context in which this conversion is possible
1>.\server.cpp(101) : error C2040: '<' : 'size_t' differs in levels of indirection from 'int *'
1>.\server.cpp(111) : warning C4018: '<' : signed/unsigned mismatch
1>.\server.cpp(115) : warning C4018: '<' : signed/unsigned mismatch
1>.\server.cpp(117) : warning C4018: '<' : signed/unsigned mismatch
1>.\server.cpp(146) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>.\server.cpp(150) : warning C4018: '<' : signed/unsigned mismatch
1>Build log was saved at "file://c:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\lab7_server2\lab7_server2\Release\BuildLog.htm"
1>lab7_server2 - 36 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
17.05.2011, 18:00     error C2440 при конвертации. Кусок кода работал в другой программе
Посмотрите здесь:

кусок кода C++
выдаёт error C2440: =: невозможно преобразовать 'int' в 'int [100] C++
C++ error C2440: не конвертируется 'LRESULT (__stdcall General::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'
C++ error C2440: 'delete' : cannot convert from 'Song' to 'void *'
C++ Нужен кусок кода
C++ Указатели. Error C2440: '=' : cannot convert from ClassAPtr to ClassA<Tclass>
C++ Error C2440: =: невозможно преобразовать 'std::string' в 'double'
Error C2440 std::vector<_Ty> C++

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

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Ответ Создать тему
Опции темы

Текущее время: 15:12. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru