What does the 'static' in "vector<static FixPt> Data1024;" standfor?

C

Cuthbert

Hi folks,

I am a newcomer to C++ and am reading a example code right now. In
this example code, the author used a lot of "vector<static DataType>
somename;". I know the static vector definition but wonder what's the
different between static vector and "vector<static xxx> xxx"? Can
anybody explain this for me? Thanks a lot.


Cuthbert
 
A

alfps

    I am a newcomer to C++ and am reading a example code right now. In
this example code, the author used a lot of "vector<static DataType>
somename;". I know the static vector definition but wonder what's the
different between static vector and "vector<static xxx> xxx"? Can
anybody explain this for me? Thanks a lot.

The usage

vector<static T> v;

is not valid standard C++.

If you're sure that the example was /exactly/ like that, then please
tell the group what book you're reading, and locate the nearest
fireplace.

There remains of course the possibility of some compiler-specific
language extension, and/or that you remember the example incorrectly.

Cheers & hth.,

- Alf
 
C

Cuthbert

Alf, thanks for your reply.

I tried to take off 'static' idenfier and compiled the source code. It
passed in VC2005pro and worked just like original code with 'static'.
Is it typo or something else? don't know.

Cuthbert
 
N

Noah Roberts

Jeff said:
And check the book's web site for errata, or email the publisher.

Another thing to remember is that a lot of schools use really old books
to teach C++, if they teach it at all. It could be some pre-standard
monstrosity.
 
J

Juha Nieminen

Christian said:
Strange enough, it compiles
fine with VC even if you disable language extensions.

What is std::vector<static something> supposed to do in VC?
 
J

jason.cipriani

  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.

Jason
 
J

jason.cipriani

  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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top