Topic: question: stl vector
Author: whtang@monica (Hung-Chai Info Company)
Date: 1995/05/18 Raw View
Hung-Chai Info Company (whtang@monica) wrote:
: The vector class doesn't parameterize any pointer type. For example,
: #include <vector.h>
: main()
: {
: vector<int *> a(1000, (int *) 0);
: for (int i = 0; i < 1000; i++)
: a[i] = new int(rand());
: for (i = 0; i < 1000; i++)
: cout << a[i] << '\t';
: cout << endl << endl;
: return 0;
: }
: compiler complaints that capacity() call invalid operand - of
: end_of_storage - begin().
: g++ -o vector vector.cc
: /opt/gnu/lib/g++-include/vector.h: In method `unsigned int vector<int *>::capacity() const':
: /opt/gnu/lib/g++-include/vector.h:77: invalid operands to binary -
: whtang@dblab.cs.nchu.edu.tw
: tommy
The problem is fixed after replace the iterator begin() by start.
I don't know why, but it works.
end_of_storage is of type const iterator.
begin() is of type const_iterator.
start is of type const iterator.
Maybe it dues to type mismatch.
whtang@dblab.cs.nchu.edu.tw
tommy
Author: whtang@monica (Hung-Chai Info Company)
Date: 1995/05/18 Raw View
The vector class doesn't parameterize any pointer type. For example,
#include <vector.h>
main()
{
vector<int *> a(1000, (int *) 0);
for (int i = 0; i < 1000; i++)
a[i] = new int(rand());
for (i = 0; i < 1000; i++)
cout << a[i] << '\t';
cout << endl << endl;
return 0;
}
compiler complaints that capacity() call invalid operand - of
end_of_storage - begin().
g++ -o vector vector.cc
/opt/gnu/lib/g++-include/vector.h: In method `unsigned int vector<int *>::capacity() const':
/opt/gnu/lib/g++-include/vector.h:77: invalid operands to binary -
whtang@dblab.cs.nchu.edu.tw
tommy