





未手動位元組對其的情況下,sizeof(結構體) = 77, 在手動對其的情況下賦值不出現崩潰, 求大佬求解!
uj5u.com熱心網友回復:
#pragma pack 指定結構體位元組對齊試試看
#pragma pack(push, 8)
typedef struct _tagxxxx_t
{
}xxxx;
#pragma pack(pop)
uj5u.com熱心網友回復:
#pragma pack 我試過不會崩潰, 結構體變數位置調整也不會出現崩潰。我只是想知道為啥string賦值會崩了uj5u.com熱心網友回復:
結構體以這種形式定義也不會出現崩潰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;
uj5u.com熱心網友回復:
這個結構體要寫深拷貝構造和多載賦值運算子uj5u.com熱心網友回復:
已經有寫了賦值運算子,這是一整個結構體代碼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;
uj5u.com熱心網友回復:
單獨測驗這個沒有問題啊, 是不是其他地方引起的越界/或類資訊被修改的操作?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/51478.html
標籤:基礎類
