![](/img/trans.png)
[英]Error[Pe167]: argument of type “uint16_t *” is incompatible with parameter of type “unsigned char *”
[英]argument of type uint8_t is incompatible with parameter of type char*
我最近一直遇到標題錯誤,但我不確定自己在做什么錯,有人有任何想法嗎? 下面的相關代碼
羅姆
//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
#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;
}
抱歉,如果這很明顯,但我在這里感到迷茫。
uint8_t
和char
是不同的類型。 (嗯-這取決於系統,但是在您的系統上它們是不同的)。 您不能將兩個名稱互換使用。
您的問題沒有提到哪行給出了錯誤,但是如果您查找該行,您會發現您正在傳遞uint8_t *
,實際上該函數期望使用char *
。
我猜應該是rom.read
。 如果是這樣,則可以使用以下方法解決問題:
rom.read( reinterpret_cast<char *>(memblock), size );
您不需要使用冗余的unsigned int
強制轉換或this->
前綴。
另一個可能的解決方案是使memblock
類型為char *
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.