array inside vector

S

sasha

Is it possible to declare array inside vector?

class Test{
private:
vector < char[12] > node;

public:
}


Thank you.
 
J

Jerry Coffin

(e-mail address removed)>, (e-mail address removed)
says...
Is it possible to declare array inside vector?

class Test{
private:
vector < char[12] > node;

public:
}

No -- to be used as an element in a vector, the type must be assignable
and copyable, and an array isn't either one.
 
P

peter koch

Is it possible to declare array inside vector?

class Test{
  private:
    vector < char[12] > node;

  public:

}

Thank you.


No - because the array is a bastard C/C++ type. It decays to easily.
What you can do is use boost::array or declare your own array:

struct char12array
{
char data[12];
};

Obviously, the boost version is by far the best - giving you a "real"
array, without having to augment the char12array struct.

/Peter
 
S

sasha

Wow, I never heard of boost array before, what source would you
recommend for libraries? I googled it and it seems like www.boost.org
is the place to get it. So how would I declare the boost array inside
a vector. Does that look ok?

vector < boost::array < char,12 > > node;

I use mingw compiler, I guess boost templates should work with it?
 
P

peter koch

Wow, I never heard of boost array before, what source would you
recommend for libraries?  I googled it and it seems likewww.boost.org
is the place to get it.  So how would I declare the boost array inside
a vector.  Does that look ok?

vector < boost::array < char,12 > > node;
Yes - that looks perfect.
I use mingw compiler, I guess boost templates should work with it?
I don't know if the mingw compiler works with boost, but I can't
imagine boost::array not working. For the final test you have to check
the boost-documentation.
And yes - www.boost.org is the place to get the stuff.

/Peter
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top