-
assertion failures
//main.cpp
#include "drinksAtWork.h"
void main(void)
{
drinksAtWork Daw;
Daw.ChooseDrink();
//Xml();
}
//drinksatwork.h
#ifndef DRINKSATWORK_H
#define DRINKSATWORK_H
#include <stdlib.h>
class drinksAtWork
{
private:
char *ch;
public:
drinksAtWork();
void ChooseDrink();
~drinksAtWork();
};
#endif
//drinksatwork.cpp
#include "drinksAtWork.h"
/*#include <file.h>*/
#include <iostream.h>
//#include <fstream.h>
void drinksAtWork::ChooseDrink()
{
cout << ch << endl;
cout << "Choose your can." << endl;
/* FILE *fp;//write equivalent code using fstream*/
cin >> ch;
}
drinksAtWork::drinksAtWork()
{
ch=new char;
ch="ff";
}
drinksAtWork::~drinksAtWork()
{
delete ch;
}
at first compiled at linked but when data was entered at the command prompt I ran into an assertion error. I pasted the line of the location of the error in Edit-Breakpoints-Data (Tab)-Enter the expression to be evaluated with the not(!) sign in front of it but it would not be accepted to be evaluated. Now after having closed the compiler and reopened it at another time it has LINK : fatal error LNK1000: unknown error; consult documentation for technical support options. Someone help?
-
Code:
ch=new char;
ch="ff";
It seems here you are allocating space on the free store for a char, and then reallocating the pointer to the start of a string literal - "ff".
now when you excecute
You no longer have access to the char you dynamically created.....therefore your proggie is crashing,
I dont know why you are setting the pointer to the start of "ff".....
if you set it to a char like so;
.......it should work