class MyStrValArray {
private:
vector<char> p;
public:
void init(const int n);
void clear();
unsigned capacity();
unsigned size();
};
int main()
{
MyStrValArray p1;
...
if(p1.capacity() == p1.size())
{
MyStrValArray p2;
p2.init(p1.size()*2);
p2 = p1;
p1.clear(); // I'm trying to delete the whole p1 instance, not the data inside p1.
}
return 0;
}
What I am trying to do is: when the memory of p1 is full, make another instance p2, with double of p1's size, copy all the data inside p1 to p2, and then remove p1.
How can I delete an instance of the class? If I use .clear(), I'm just deleting all the elements inside, not the instance itself. Is there any way to delete an instance?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…