简体   繁体   English

uint8_t类型的参数与char *类型的参数不兼容

[英]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_tchar是不同的类型。 (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.

相关问题 错误[P​​e167]:“ uint16_t *”类型的参数与“ unsigned char *”类型的参数不兼容 - Error[Pe167]: argument of type “uint16_t *” is incompatible with parameter of type “unsigned char *” “ int”类型的参数与“ char”类型的参数不兼容 - Argument of type 'int' is incompatible with parameter of type 'char' “char *”类型的参数与“LPWSTR”类型的参数不兼容 - Argument of type “char *” is incompatible with parameter of type “LPWSTR” “ char *”类型的参数与“ STARTUPINFO”类型的参数不兼容 - Argument of type “char *” is incompatible with parameter of type “STARTUPINFO” char类型的参数与参数类型LPWSTR不兼容 - Argument of type char is incompatible with parameter type LPWSTR 如何检查uint8_t是否作为类型而不是unsigned char存在? - How to check if uint8_t exists as a type, instead of unsigned char? 如何检测参数包中uint8_t的类型 - How to detect type of uint8_t in parameter pack “unsigned char *”类型的参数与“const char *”类型的参数不兼容 - Argument of type "unsigned char *" is incompatible with parameter of type "const char *" “ const char **”类型的参数与“ const char *”类型的参数不兼容 - Argument of type “const char **” is incompatible with parameter of type “const char *” 类型“ const char *”的参数与类型“ char *”的参数不兼容。 但为什么? :( - Argument of type “const char*” is incompatible with parameter of type “char*”. But why? :(
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM