【发布时间】:2014-12-25 08:49:09
【问题描述】:
我有这个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
【问题讨论】:
-
大概
speicher持有void *。 -
请在错误日志中粘贴行号和准确代码 +/- 5 行,围绕产生错误的行。
-
speicher的类型是什么? -
unsigned int hexzahl = (cout << dec << read(index));不应该编译。 -
请发布完整的错误信息,不要转述。
note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match> operator void*() const是错误信息的重要部分。
标签: c++