私はこのエラーが発生しており、コードエディタでエラーが発生していないので修正方法がわかりません。私は同様の問題を探しましたが、ここで解決策を適用する方法を理解するのはまだ難しいです。私は数時間、私のコードを変更しようとしましたが、役に立たない。どんな助けもありがとう。私は下記の.hと.cppファイルを提供しています。*** glibcが検出されました*** ms2:free():無効なポインタ:0xb7526ff4 ***
ErrorMessage.h
#ifndef SICT_ERRORMESSAGE_H
#define SICT_ERRORMESSAGE_H
#include <iostream>
namespace sict {
class ErrorMessage {
char* message_; //pointer that holds the address of the message stored in current object
public:
explicit ErrorMessage(const char* errorMessage = nullptr); //receive address of a C-style nullterminate string holding an error message
ErrorMessage(const ErrorMessage& em) = delete; //deleted copy constructor that prevents copying of an ErrorMessage object
ErrorMessage& operator=(const ErrorMessage& em) = delete; //deleted assignment operator that prevents assignment of ErrorMessage object to current object
virtual ~ErrorMessage(); //deallocates any memory that has been dynamically allocated by the current object
void clear(); //clears any message stored by current object and initialize object to safe, empty state
bool isClear() const; //return true if object is in a safe, empty state
void message(const char* str); //stores a copy of the C-style string pointed to by str
const char* message() const; //return address of the message stored in current object
};
//helper operator
std::ostream& operator<<(std::ostream& os, const ErrorMessage& err);
}
#endif
ErrorMessage.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include "ErrorMessage.h"
namespace sict {
ErrorMessage::ErrorMessage(const char* errorMessage) {
if(errorMessage == nullptr) {
message_ = nullptr;
}
else {
message(errorMessage);
}
}
ErrorMessage::~ErrorMessage() {
delete [] message_;
}
void ErrorMessage::clear() {
delete [] message_;
message_ = nullptr;
}
bool ErrorMessage::isClear() const {
if(message_ == nullptr) {
return true;
}
else {
return false;
}
}
void ErrorMessage::message(const char* str) {
delete [] message_;
message_ = new char[strlen(str) + 1];
strcpy(message_, str);
}
const char* ErrorMessage::message() const {
return message_;
}
std::ostream& operator<<(std::ostream& os, const ErrorMessage& err) {
if(!err.isClear()) {
os << err.message();
}
return os;
}
}
今、実際にはC++ですが、 'std :: string'を使用する代わりに、このすべてのことを行う有効な理由はありますか? – Jack
コードエディタのクリーンな健康状態は、あなたのプログラムがバグフリーであることを意味し、本当にショックを受けていると思われる場合は、また、表示されたコードよりもプログラムに多くのものがあることは明らかです。なぜあなたのコードの他の部分ではなく、示されたコードに問題があると正確に信じますか? –
コードの唯一の部分はメインファイルですが、何らかの形で変更されることはありません。つまり、エラーはコード – Glaz