Hello there stackOverflow.
I am a noob when it comes to c++ and today i tried to compile my first program including classes. This ofcourse gave me an error and i don't really know what i did wrong since its my first time compling a class program :P
i tried to google it and it said something about either the DLL.'s are building wrong? (i got it all in debug mode, so it can't be that). So the other option is: i might be freeing the memory wrongly or something like that, can anyone explain where i did wrong?
i tried to compare the code to the tutorial i found. But that didn't help. (the tutorial im referring to is: http://www.youtube.com/watch?v=vz1O9nRyZaY ). The error i'm getting is
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());
}
}
and my source code / header files are:
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)
}