C++ msvr100.dll空闲(void*pblock)
您好,这里是stackOverflow。C++ msvr100.dll空闲(void*pblock),c++,C++,您好,这里是stackOverflow。 我是一个NoOB当谈到C++时,今天我尝试编译我的第一个程序,包括类。这当然给了我一个错误,我真的不知道我做错了什么,因为这是我第一次完成一个课程计划:P 我试着用谷歌搜索它,它说要么DLL构建错误?(我都是在调试模式下得到的,所以不可能是那样)。所以另一个选择是:我可能是错误地释放了内存或者类似的东西,有人能解释我哪里做错了吗 我试图将代码与我找到的教程进行比较。但那没用。(我指的教程是:)。我得到的错误是 void __cdecl _free_bas
我是一个NoOB当谈到C++时,今天我尝试编译我的第一个程序,包括类。这当然给了我一个错误,我真的不知道我做错了什么,因为这是我第一次完成一个课程计划:P 我试着用谷歌搜索它,它说要么DLL构建错误?(我都是在调试模式下得到的,所以不可能是那样)。所以另一个选择是:我可能是错误地释放了内存或者类似的东西,有人能解释我哪里做错了吗 我试图将代码与我找到的教程进行比较。但那没用。(我指的教程是:)。我得到的错误是
void __cdecl _free_base (void * pBlock)
{
int retval = 0;
if (pBlock == NULL)
return;
RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));
retval = HeapFree(_crtheap, 0, pBlock);
if (retval == 0)
{
errno = _get_errno_from_oserr(GetLastError());
}
}
我的源代码/头文件是:main.cpp
#include <iostream>
#include <string>
#include "conio.h"
#include <crtdbg.h>
#include "Tax.h"
using namespace std;
int main()
{
string name;
double tax;
double income;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your annually income: ";
cin >> income;
cout << "Enter your tax rate in pure numbers: ";
cin >> tax;
Tax Customer_1(name, income, tax);
cout << endl << "Customer name: " << Customer_1.getName() << endl <<
"Income annually: " << Customer_1.getIncome() << endl <<
"Tax percent(in real numbers): " << Customer_1.getTax() << endl <<
"Your income after tax, per month is: " << Customer_1.calculateTax() << endl;
cout << endl;
_getch();
return 0;
}
我(稍微)修改了您的代码以解决此问题,请尝试以下操作:
税.h:
#include <iostream>
#include <string>
#ifndef TAX_H
#define TAX_H
class Tax
{
public:
//Default constructor
Tax();
//Overload constructor
Tax(std::string, double, double);
//destructor
~Tax();
//Accessor functions
std::string getName() const;
double getIncome() const;
double getTax() const;
//Mutator functions
void setName(std::string);
void setIncome(double);
void setTax(double);
double calculateTax() const;
private:
//Member variables
std::string newName;
double newIncome;
double newTax;
};
#endif
main.cpp
#include "tax.h" // <iostream> and <string> are here
// never put 'using namespace std' in a header file
using namespace std;
int main()
{
string name;
double tax;
double income;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your annually income: ";
cin >> income;
cout << "Enter your tax rate in pure numbers: ";
cin >> tax;
Tax Customer_1(name, income, tax);
cout << endl << "Customer name: " << Customer_1.getName() << endl <<
"Income annually: " << Customer_1.getIncome() << endl <<
"Tax percent(in real numbers): " << Customer_1.getTax() << endl <<
"Your income after tax, per month is: " << Customer_1.calculateTax() << endl;
cout << endl;
return 0;
}
虽然你的意图是让控制台暂停(与程序刚刚结束),你可能想考虑其他(更优雅)的解决方案,但这超出了这个问题的范围。
几个注意事项:您的程序在不处于调试模式时工作的原因(即您进入“发布”)是您包含了
头;此文件仅在调试配置中有效,如果您没有在其中使用任何内容(代码中没有),则不应该包含它。我还使用名称空间std取出了
在您的tax.h
文件中
我希望这能帮助你你犯了什么错误?嘿,乔。我可以很好地编译这个程序。但是在我退出它之后,我得到了以下错误:“未处理的异常0xC000005”(我认为是内存错误)。它将我引导到一个“free.c”文件,其中说“如果(retval==0){errno=errno=\u从_oserr(GetLastError());}”整个问题都包含在问题的顶部。顺便说一句,如果我听起来有点离题,很抱歉,但我真的很累了。你不做任何动态分配,在通读几遍之后,我觉得其他一切都很好。。。所以我被难住了。你确定生成错误的代码就是上面的代码吗?你没有在析构函数中或其他地方调用
delete
?我只是尝试创建一个新项目并复制粘贴上面的代码,经过编译后,在关闭控制台窗口后发生了相同的错误。不,我什么都没变。嘿,特克斯,帮帮忙。谢谢你的回复和建议。我将在将来注意到这些,并且在我们正在进行的当前项目中也尝试这样做。但不幸的是,我仍然得到了同样的错误:/我在VisualStudio2010上,我试图切换到2012年,在那里我再次得到了一个错误。这次,小错误箭头将我指向一个名为(_Ptr)的文本,当我将鼠标悬停在它上面时,它会显示:Facet_Base::Vector deleting destructor(unsigned int)。这到底是什么意思?我是否应该更改类型,因为它无法保存数字,或者发生了什么?thx for ur help您可以从命令行编译吗?您可以通过打开命令提示符并键入cl
进行检查,如果它显示,那么您可以尝试使用命令行编译简单的tax.cpp和main.cpp文件,例如:cl.exe tax.cpp main.cpp/EHsc
。。这将生成一个可以运行的main.exe。如果命令行编译成功并且没有任何错误(应该是这样),那么VisualStudio可能会添加更多的编译器选项(通过项目设置/etc),而不是您所认为的/need.hmm nope甚至无法从命令行编译。它只是说“错误:无法确定VS Common Tools文件夹的位置。”在顶部,当我尝试编写cl时,它说它未被识别为intern或extern命令、程序或批处理文件
#include <iostream>
#include <string>
#ifndef TAX_H
#define TAX_H
class Tax
{
public:
//Default constructor
Tax();
//Overload constructor
Tax(std::string, double, double);
//destructor
~Tax();
//Accessor functions
std::string getName() const;
double getIncome() const;
double getTax() const;
//Mutator functions
void setName(std::string);
void setIncome(double);
void setTax(double);
double calculateTax() const;
private:
//Member variables
std::string newName;
double newIncome;
double newTax;
};
#endif
#include "tax.h"
Tax::Tax()
{
newIncome = 0.0;
newTax = 0.0;
}
Tax::Tax(std::string name, double income, double tax)
{
newName = name;
newIncome = income;
newTax = tax;
}
Tax::~Tax() {}
std::string Tax::getName() const
{
return newName;
}
double Tax::getIncome() const
{
return newIncome;
}
double Tax::getTax() const
{
return newTax;
}
void Tax::setName(std::string name)
{
newName = name;
}
void Tax::setIncome(double income)
{
newIncome = income;
}
void Tax::setTax(double tax)
{
newTax = tax;
}
double Tax::calculateTax() const
{
return (( newIncome - ( newIncome * (newTax / 100))) / 12);
}
#include "tax.h" // <iostream> and <string> are here
// never put 'using namespace std' in a header file
using namespace std;
int main()
{
string name;
double tax;
double income;
cout << "Enter your name: ";
cin >> name;
cout << "Enter your annually income: ";
cin >> income;
cout << "Enter your tax rate in pure numbers: ";
cin >> tax;
Tax Customer_1(name, income, tax);
cout << endl << "Customer name: " << Customer_1.getName() << endl <<
"Income annually: " << Customer_1.getIncome() << endl <<
"Tax percent(in real numbers): " << Customer_1.getTax() << endl <<
"Your income after tax, per month is: " << Customer_1.calculateTax() << endl;
cout << endl;
return 0;
}
...
cin.clear(); // clear buffer for erroneous 'enter' presses
cin >> name; // console will pause until you press enter
return 0;