c语言程序运行错误内存,如何在C程序中修复此堆栈溢出错误?

所以,我是C的初学者…我认为我已经牢牢掌握了动态内存分配,但我想我没有.我在网上搜索了很多解决方案,但我仍然无法解决我的问题.我一直收到错误0xC00000FD:运行调试时堆栈溢出.

我很确定这个问题与我在默认构造函数中分配内存的方式有关,但也许是其他的东西.我想我需要更深入的见解.

任何帮助或暗示确定问题将不胜感激.

这是一个从用户输入计算矩形的面积和周长的简单程序.

这是头文件:

#pragma once

class my_Rectangle

{

private:

float m_area;

float m_perimeter;

float m_length;

float m_width;

void update_rec();

my_Rectangle*tempSTORE;

public:

float calc_area(float length,float width);

float calc_perim(float length,float width);

void change_RECTsize(float length,float width,my_Rectangle tempSTORE);

my_Rectangle(); //constructor

my_Rectangle(float length,float width);

~my_Rectangle(); //destructor

};

这是类成员定义文件:

#include "StdAfx.h"

#include "my_Rectangle.h"

#include

//using namespace std;

//This function calculates the area

float my_Rectangle::calc_area(float length,float width)

{

float area = width * length;

std::cout<

The area of the rectangle is: "<

return area;

}

//This function calculates the perimeter

float my_Rectangle::calc_perim(float length,float width)

{

float perimeter=(2*length)+(2*width);

std::cout<

The perimeter of the rectangle is "<

return perimeter;

}

//this function changes the size of the rectangle

void my_Rectangle::change_RECTsize(float length,float width,my_Rectangle tempSTORE)

{

tempSTORE.m_length=length;

tempSTORE.m_width=width;

my_Rectangle::calc_area(length,width);

my_Rectangle::calc_perim(length,width);

}

my_Rectangle::my_Rectangle() //default constructor

{

tempSTORE=new my_Rectangle;

tempSTORE->m_length=0.00;

tempSTORE->m_width=0.00;

tempSTORE->m_area=0.00;

tempSTORE->m_perimeter=0.00;

}

my_Rectangle::my_Rectangle(float length,float width) //initialized constructor

{

tempSTORE=new my_Rectangle;

tempSTORE->m_length=length;

tempSTORE->m_width=width;

calc_area(length,width);

calc_perim(length,width);

}

my_Rectangle::~my_Rectangle() //destructor

{

delete tempSTORE;

std::cout<

The memory has been freed!!"<<:endl>

这是客户端文件:

#include "stdafx.h"

#include "my_Rectangle.h"

#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

float xlength,xwidth;

cout<

cout<

cout<>xlength;

cout<>xwidth;

cout<

cout<

my_Rectangle userRECT(xlength,xwidth);

reTRY:

int user_choice;

cout<

cout<

cout<

cout<

cin>>user_choice;

switch (user_choice)

{

case 1:

cout<

cout<>xlength;

cout<>xwidth;

cout<

Rectangle Information:"<

cout<

userRECT.change_RECTsize(xlength,xwidth,userRECT);

break;

case 2:

exit(1);

break;

default: cout<

That is not a valid option. Please try again!" ;

goto reTRY;

break;

}

cin.get();cin.get();

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值