未手动字节对其的情况下,sizeof(结构体) = 77, 在手动对其的情况下赋值不出现崩溃, 求大佬求解!

解决方案 »

  1.   

    #pragma pack 指定结构体字节对齐试试看#pragma pack(push, 8)
    typedef struct _tagxxxx_t
    {
    }xxxx;
    #pragma pack(pop)
      

  2.   

    #pragma pack 我试过不会崩溃, 结构体变量位置调整也不会出现崩溃。我只是想知道为啥string赋值会崩了
      

  3.   

    结构体以这种形式定义也不会出现崩溃
    int iLine;
    int iCorner;
    int total_layer;
    float pixel_to_mm;
    float min_length;
    float max_length;
    float max_angle_thresh; bool isDrawBarcode;   // 是否在图片上绘制条码 bool isDrawLine;
    bool isShowData;
    bool isShowAngle;
    bool isDetectAngle:2; cv::Rect detected_rect;
    std::string strBarcode;
      

  4.   

    已经有写了赋值操作符,这是一整个结构体代码typedef struct stInputParams
    {
    int iLine;
    int iCorner;
    int total_layer;
    float pixel_to_mm;
    float min_length;
    float max_length;
    float max_angle_thresh; bool isDrawBarcode;   // 是否在图片上绘制条码 bool isDrawLine;
    bool isShowData;
    bool isShowAngle;
    bool isDetectAngle; cv::Rect detected_rect;
    std::string strBarcode; stInputParams()
    {
    iLine = 1;
    iCorner = 1;
    total_layer = 5;
    pixel_to_mm = 0.01f;
    min_length = 0.1;
    max_length = 1.4f;
    max_angle_thresh = 90.0f; isDrawBarcode = false; isDrawLine = true;
    isShowData = true;
    isDetectAngle = true;
    isShowAngle = true;
    detected_rect = cv::Rect(0, 0, 0, 0);
    strBarcode = std::string("ERROR");
    } stInputParams operator=(const stInputParams& params)
    {
    iLine = params.iLine;
    iCorner = params.iCorner;
    total_layer = params.total_layer;
    pixel_to_mm = params.pixel_to_mm;
    min_length = params.min_length;
    max_length = params.max_length;
    max_angle_thresh = params.max_angle_thresh; isDrawBarcode = params.isDrawBarcode; isDrawLine = params.isDrawLine;
    isShowData = params.isShowData;
    isDetectAngle = params.isDetectAngle;
    isShowAngle = params.isShowAngle;
    detected_rect = params.detected_rect;
    strBarcode = params.strBarcode; return(*this);
    }}stInputParams;