msvcr100.dll免费(void * block)

时间:2014-02-04 01:56:59

标签: c++

你好stackOverflow 当谈到c ++时,我是一个菜鸟,今天我尝试编写包括类的第一个程序。这个当然给了我一个错误,我不知道自从我第一次参加课程以来我做错了什么:P

我试图谷歌它,它说了一些关于DLL。的建设错了吗? (我在调试模式下得到了所有,所以它不可能)。所以另一个选择是:我可能会错误地释放内存或类似的内容,任何人都可以解释我做错了什么?

我试图将代码与我找到的教程进行比较。但这没有帮助。 (我指的教程是:http://www.youtube.com/watch?v=vz1O9nRyZaY)。我得到的错误是

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;
}

Tax.h:

#include <iostream>
#include <string>

using namespace std;

#ifndef TAX_H
#define TAX_H

class Tax
{
public:

//Default constructor
Tax();

//Overload constructor
Tax(string, double, double);

//destructor
~Tax();

//Accessor functions
string getName() const;

double getIncome() const;

double getTax() const;

//Mutator functions
void setName(string);

void setIncome(double);

void setTax(double);

double calculateTax() const;

private:

//Member variables
string newName;
double newIncome;
double newTax;
};

#endif

Tax.cpp

     #include "Tax.h"

Tax::Tax()
{
newIncome = 0.0;
newTax = 0.0;
}

Tax::Tax(string name, double income, double tax)
{
newName = name;
newIncome = income;
newTax = tax;
}

Tax::~Tax()
{
}

string Tax::getName() const
{
    return newName;
}

double Tax::getIncome() const
{
return newIncome;
}

double Tax::getTax() const
{
return newTax;
}

void Tax::setName(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); // ((68400 - ( 68400 * (38/100 = 0.38))) / 12)
}

1 个答案:

答案 0 :(得分:0)

我(略)修改了你的代码,试试这个:

tax.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

tax.cpp:

#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);
}

的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;
}

记下已更换的内容和您使用的标题;通过代码末尾的_getch()来判断,我假设您正在使用它,以便您的控制台窗口在调试时不会消失;如果是这种情况,你可以用cin和你已经拥有的字符串做一些事情:

...
cin.clear(); // clear buffer for erroneous 'enter' presses
cin >> name; // console will pause until you press enter
return 0;

虽然如果你的意图是实际让控制台暂停(相对于程序刚刚结束),你可能想要考虑其他(更优雅)的解决方案,但这超出了这个问题的范围。

一些注意事项:你的程序在不处于调试模式时工作的原因(即你去了&#39;发布&#39;)是你包含<crtdbg.h>标题;此文件仅在调试配置中有效,如果您没有使用其中的任何内容(您不在代码中),则不应该包含该文件。我还将using namespace std;文件中的tax.h作为there are numerous reasons not to include using namespace std in a header取出。

我希望可以提供帮助

相关问题