[英]argument of type uint8_t is incompatible with parameter of type char*
I've been getting the title error recently and I'm not quite sure what I'm doing wrong, anyone have any ideas? 我最近一直遇到标题错误,但我不确定自己在做什么错,有人有任何想法吗? relevant code below
下面的相关代码
Rom.h 罗姆
//Rom.h
#pragma once
#include <fstream>
struct ROM {
uint8_t* memblock;
std::fstream rom;
std::streampos size;
int flag;
void ROM::LoadROM(std::string path, int flag);
void ROM::BinaryDump(std::string path, std::streampos size);
}
Rom.cpp 罗姆
//Rom.cpp
#include <iostream>
#include "Rom.h"
void ROM::LoadROM(std::string path, int flag) {
this->rom.open(path, std::ios::in | std::ios::binary | std::ios::ate);
if (rom.is_open()) {
this->size = rom.tellg();
std::cout << "\nThe Rom is " << rom.tellg() << " byte(s) long." << std::endl;
this->memblock = new uint8_t[(unsigned int)this->size];
std::cout << rom.tellg() << " Bytes of memory have been allocated" << std::endl;
rom.seekg(0, std::ios::beg);
rom.read(this->memblock, (unsigned int)this->size);
std::cout << "The contents of the file are stored in memory" << std::endl;
rom.close();
if (flag == 0) {
}
else {
BinaryDump(path, this->size);
}
}
}
void ROM::BinaryDump(std::string path, std::streampos size) {
std::fstream binDump(path, std::ios::out | std::ios::binary);
binDump.write(this->memblock, size);
delete[] this->memblock;
binDump.close();
std::cout << "The ROM has been dumped" << std::endl;
}
Sorry if this is completely obvious but I feel lost here. 抱歉,如果这很明显,但我在这里感到迷茫。
uint8_t
and char
are different types. uint8_t
和char
是不同的类型。 (Well - this is system dependent, but on your system they are different). (嗯-这取决于系统,但是在您的系统上它们是不同的)。 You cannot use the two names interchangeably.
您不能将两个名称互换使用。
Your question did not mention what line gave the error, but if you look that up you will find that you are passing uint8_t *
where in fact the function expects char *
. 您的问题没有提到哪行给出了错误,但是如果您查找该行,您会发现您正在传递
uint8_t *
,实际上该函数期望使用char *
。
I guess it would be rom.read
. 我猜应该是
rom.read
。 If so then you could fix the problem with: 如果是这样,则可以使用以下方法解决问题:
rom.read( reinterpret_cast<char *>(memblock), size );
You do not need to use redundant unsigned int
casts or this->
prefixes. 您不需要使用冗余的
unsigned int
强制转换或this->
前缀。
Another possible solution would be to make memblock
have type char *
. 另一个可能的解决方案是使
memblock
类型为char *
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.