Try to avoid single-letter variables like 'l'. I mistook it for a 1. At least call it something like 'len', that way people will immediately recognize it.
Are you allowed to just use strings instead of char arrays?
Your main issue is that you are copying your date object when you pass it to show, but this then calls the destructor for the copied object, which deletes the same dynamic memory as the original object.
When dealing with dynamic memory or other unmanaged resources, you should follow the "rule of three" (AKA "rule of five", but we can ignore move constructors for learning purposes).
https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)
To avoid making a copy, you can pass date by reference
1 2 3 4
|
show(date& x)
{
...
}
|
Even better would be to make your get function be const,
1 2 3 4
|
char *get() const
{
return p;
}
|
And then pass by const reference
1 2 3 4
|
show(const date& x)
{
...
}
|
But passing by copy (value) should not break the code, so you should implement a copy constructor.
Also, on line 19,
p = new char [l];
failed, it would throw an exception, not return null, so your if statement is dead code.
I also question the broad design of the code itself. You call this a "date" object, yet all it does is hold a string that was passed to it. That string could be "puppy". Usually, people would want to use "dates" for actually date/time calculations. See an example of date/time library at:
https://howardhinnant.github.io/date/date.html