文章分类 -  C++ Exception

摘要:我在构造方法中,对char * c 进行申请内存时,假如 “12345”赋值给 c时,就要申请6块内存,来存储12345,假如我只申请了 5块内存时,没有为字符串结尾的"\n"也申请一块内存时,在析构函数释放内存时,就会把出现这种情况;出错的例子:baseString::baseString(const char * c ,int n){ num = n; label = new char[std::strlen(c)]; // 出错了, label = new char[std::strlen(c)+1];之后就正确了 std::strcpy(label,c);}下面的这 阅读全文

posted @ 2014-02-23 11:41 fantiejun0436 阅读(160) 评论(0) 推荐(0)

摘要://头文件中顶一个类class baseString{private: char * label ; //定义了一个指针变量,但是还没有具体的指向某一块内存呢 int num ;public: baseString(); baseString( baseString & bs); baseString( const char * c ,int n ); virtual ~baseString();};//在.cpp文件当中,我定义了这个类的构造方法,出错的变时此处。baseString::baseString( const char * c ,int n){ delete [] lab 阅读全文

posted @ 2014-02-22 13:59 fantiejun0436 阅读(105) 评论(0) 推荐(0)

摘要:一个对象,按值传递给一个函数,称为这个函数的局部变量,函数结束后,这个局部变量被析构函数给释放了一次,然后整个买main函数结束之后,再次释放这个对象是,就会报这个错。 _BLOCK_TYPE_IS_VALID 阅读全文

posted @ 2014-02-21 05:52 fantiejun0436 阅读(108) 评论(0) 推荐(0)

导航