Hi,
I am relatively new at c++. I am writing a code with
constructors and i'm with some problems in this part.
I'm using Microsoft Visual c++ 2008.
Next code compiles right, but there is problems with
execution.
I think it is because i'm not working right with
constructors and the strcpy statement does not its
right job.
#include <iostream>
using namespace std;
class caract{
char *temp;
public:
caract(void);
~caract(void);
void assign(char *str);
void show(void);
};
caract::caract(void)
{ temp = "hello ";}
caract::~caract(void)
{ cout << "destroyed\n";}
void caract::assign(char *str)
{ cout << temp;
cout << str << "\n";
strcpy(temp,str);
cout << temp << "\n";}
void caract::show(void)
{ cout << temp << "show \n";}
int main()
{ caract a, b, c;
a.assign("mike");
b.assign("however");
c.show();
return 0;}
If some one could help me, I appreciate.
I am relatively new at c++. I am writing a code with
constructors and i'm with some problems in this part.
I'm using Microsoft Visual c++ 2008.
Next code compiles right, but there is problems with
execution.
I think it is because i'm not working right with
constructors and the strcpy statement does not its
right job.
#include <iostream>
using namespace std;
class caract{
char *temp;
public:
caract(void);
~caract(void);
void assign(char *str);
void show(void);
};
caract::caract(void)
{ temp = "hello ";}
caract::~caract(void)
{ cout << "destroyed\n";}
void caract::assign(char *str)
{ cout << temp;
cout << str << "\n";
strcpy(temp,str);
cout << temp << "\n";}
void caract::show(void)
{ cout << temp << "show \n";}
int main()
{ caract a, b, c;
a.assign("mike");
b.assign("however");
c.show();
return 0;}
If some one could help me, I appreciate.