我正在尝试跟踪我的类中称为序列的已使用元素。 Sequence是一个使用数组实现的自定义矢量样式类。它有front()back()....几乎所有的向量函数。我不确定如何跟踪阵列中使用的斑点。我试图为我的.empty()布尔函数执行此操作。 所以总之我有类似的东西
Sequence s = new Sequence(5); // create a sequence
s[0] = 10;
s[3] = 45;
//so the sequence s has the values <10, junk, junk, 45, junk> in that order
s.size(); // returns the overall capacity of the sequence (i.e. in this case 5)
s.used(); // should return 2 since only 2 elements are using indexes in the array
/*used can be used for the Boolean class empty easily and other operations.. but
*the problem lies with how to increment a "used" variable such that normal operations
*like operator[] overloaded wont increment used but assignments will.
*Can an overloaded assignment not effect functionality just increment used by one?
*/