Witam
Nie potrafię zrozumieć, dlaczego program się wysypuje podczas usuwania tablicy znaków.
CRot13 szyfr;
szyfr.ChangeAlphabet(v);
ClassicCrypt.cpp
CAlphabet::CAlphabet()
{
size = 0;
sign = NULL;
}
CAlphabet::CAlphabet(unsigned sz)
{
size = sz;
cout << "Konstruktor wywolany z parametrem" << size << endl;
sign = new char[sz];
for(int i = 0; i < size; i++)
sign[i] = 'a';
}
CAlphabet::CAlphabet(const CAlphabet& ca)
{
size = ca.size;
sign = ca.sign;
}
CAlphabet::~CAlphabet()
{
delete []sign;
}
void CAlphabet::ChangeSize(unsigned sz)
{
delete []sign; //TU pojawia się problem.
sign = new char[sz];
size = sz;
}
int CAlphabet::GiveSize()
{
return size;
}
void CAlphabet::Fill(const vector<char>& v)
{
for(int i = 0; i < v.size(); i++)
sign[i] = v[i];
}
void CAlphabet::ChangeAlphabet(const vector<char>& v)
{
ChangeSize(v.size());
Fill(v);
}
void CAlphabet::Show()
{
for(int i = 0; i < size; i++)
cout << i << ". " << sign[i] << endl;
}
void CAlphabet::ChangeElement(int element, char sgn)
{
sign[element] = sgn;
}
//CCipher-----------------------------------------------------------------------------------
CCipher::CCipher()
{
plain = new short[0];
alphabet = new CAlphabet(1);
textLenght = 0;
}
CCipher::CCipher(string& text, CAlphabet& alph)
{
*alphabet = alph;
Convert(text);
}
CCipher::CCipher(const CCipher &ciph)
{
plain = ciph.plain;
alphabet = ciph.alphabet;
textLenght = ciph.textLenght;
}
CCipher::~CCipher()
{
delete []plain;
}
void CCipher::ChangeAlphabet(const vector<char>& v)
{
delete alphabet;
alphabet->ChangeAlphabet(v);
}