错误消息"invalid conversion from ‘void*’ to ‘unsigned int’"
Error Message "invalid conversion from ‘void*’ to ‘unsigned int’"
我有这个unsigned int
函数(它是任务的给定函数)
// read data from virtual memory
unsigned int read(const int index) {
return speicher[index];
}
在speicher[index]
中是一个数字,我必须将其解码为4个分量。第一个分量是speicher[index] mod 16
的值,第二个分量是我认为的(speicher[index])/(16*16)mod16
的值,依此类推
另一个带有错误消息的示例。也许我不明白这个功能的作用:
对我来说,函数read(const int index)
应该返回一个无符号整数,我可以像";正常的";程序中的其他无符号整数。
unsigned int index = 0;
unsigned int test = 1;
do {
unsigned int hexzahl = read(index);
test = read(index);
index = index + 1;
} while (index <= 255 && read(index) != 0);
// 37 actually i want, that the program breaks if the content of read(index) is 0
我无法理解错误信息:
main.cpp:在函数"int main()"中:
main.cpp:37:错误:ISO C++禁止在指针和整数之间进行比较
main.cpp:37:错误:从"char*()(const-char,int)"到"int"的转换无效
main.cpp:37:错误:初始化"unsigned int memory_read(int)"的参数1
您希望它能做什么?
unsigned int hexzahl = (cout << dec << read(index));
这将打印该值,然后尝试将cout
流的状态分配给一个整数。这毫无意义,这就是为什么它不会编译。
如果您想将hexzahl
设置为read
的结果,那么只需执行以下操作:
unsigned int hexzahl = read(index);
如果你想打印值,那么就单独打印:
cout << dec << hexzahl;
如果您想要read
的结果之外的其他内容,请更新问题以描述您正在尝试做什么。
错误是由于以下语句造成的:
unsigned int hexzahl = (cout << dec << read(index));
cout
的返回类型为void *
。您正试图将void *
分配给unsigned int
,这就是为什么,您发现了错误。
上述语句在C printf
中是允许的,但在C++cout
中不允许。
unsigned int hexzahl = (printf("%u%u", dec,read(index)); //In C language
printf
返回控制台上打印的字符数,该控制台是unsigned int
。你可能正在C++中尝试同样的方法,这是不可能的。
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- 调用专用模板时出错"no matching function for call to [...]"
- C++ Singleton - Prevent ::instance() to variable
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- nng to pynng pub/sub. 客户端未收到任何消息
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- Qt3D:"Mesh is empty, nothing to load"消息
- 添加 cpp11 插件时出现错误消息"Undefined reference to boost (...)"
- 将 2D 数组插入 std::vector 时"cannot convert from 'const GLfloat [12]' to '_Objty'"错误消息
- 错误消息"Undefined reference error to" C++
- 错误消息"undefined reference to 'List::a'"
- QCamera::start给出神秘的"failed to start"日志消息
- 为什么我会收到此错误消息:"undefined reference to `PerformChat(char*, char*, char*, char*, char*)'"
- 错误消息"incompatible types when assigning to type ‘char[100]’ from type ‘char *’"
- 在C++,我收到一条消息"error: 'void*' is not a pointer-to-object type"
- 错误消息"invalid conversion from ‘void*’ to ‘unsigned int’"
- 为什么我会收到"Unable to find an entry point named 'SquareRoot' in DLL"消息?