Re: What does the 'static' in "vector<static FixPt> Data1024;" stand
for?
On Dec 30, 2:17 pm, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.com> wrote:
On Dec 30, 1:45 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
Christian Hackl wrote:
Strange enough, it compiles
fine with VC even if you disable language extensions.
What is std::vector<static something> supposed to do in VC?
I don't *think* it does anything, as this program compiles and runs
with no issues:
== BEGIN CODE ==
#include <cassert>
#include <vector>
#include <typeinfo>
using namespace std;
class A { };
int main () {
A a;
vector<A> as(1);
vector<static A> sas(1);
assert(typeid(as) == typeid(sas));
assert(typeid(as[0]) == typeid(sas[0]));
as.push_back(a);
sas.push_back(a);
}
== END CODE ==
It seems to be ignored. Also, FWIW, typeid(sas).name() and typeid(sas
[0]).name() return:
sas = class std::vector<class A,class std::allocator<class A> >
sas[0] = class A
I wonder what book he's reading.
Also it does not affect the storage duration of vector elements or
anything like that (was wondering if maybe a VC bug was about to be
revealed). The following program fills 3 vectors with [1 2 3], [4 5
6], and [7 8 9] respectively, and prints them to verify that that is
indeed their contents:
== BEGIN CODE ==
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int next () {
static int n;
return ++n;
}
ostream & operator << (ostream &s, const vector<int> &v) {
copy(v.begin(), v.end(), ostream_iterator<int>(s, " "));
return s << endl;
}
int main () {
vector<int> a(3);
vector<static int> b(3);
vector<static int> c(3);
generate(a.begin(), a.end(), next);
generate(b.begin(), b.end(), next);
generate(c.begin(), c.end(), next);
cout << a << b << c;
}
== END CODE ==
The expected output is produced:
1 2 3
4 5 6
7 8 9
This is VC 2008. I suppose it's a bug that it accepts invalid code.
Jason