Re: Compilation problem when upgrading from g++ 3.3 to g++ 3.4

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 11/16/04


Date: Tue, 16 Nov 2004 08:00:13 -0000


"Alex Vinokur" <alexvn@big-foot.com> wrote in message
news:2vtovqF2pe8alU1@uni-berlin.de...
> Hi,
>
> The code below has no problem with GNU g++ 3.3,
> but it has a problem with GNU g++ 3.4.
>
> Any suggestions?

Arrays cannot be members of STL containers because they are not copyable or
assignable. No idea why g++ 3.3 allowed it in the first place.

>
> ------ foo.cpp ------
> #include <vector>
> using namespace std;
>
> typedef char foo_t[3];
> #define ELEM1 "ab"
> #define ELEM2 "cd"
>
> const foo_t a[] = {ELEM1, ELEM2};
> const vector<foo_t> v = vector<foo_t>(a, a + sizeof (a)/sizeof (*a));
>
> int main()
> {
> return 0;
> }
> ---------------------
>

Try something like this

class Char3
{
public:
    Char3(const char*);
    char operator[](size_t i);
    char c[3];
};

const Char3 a[] = {ELEM1, ELEM2};
const vector<Char3> v = vector<Char3>(a, a + sizeof (a)/sizeof (*a));

john



Relevant Pages

  • Re: Clean code vs. efficiency
    ... > instead of character arrays. ... The default STL ... In general, the STL containers are extremely fast, and might be faster than ... The STL allocators let you use pool allocators, but you can also that by ...
    (comp.lang.cpp)
  • Re: Lookup Table
    ... > I'm trying to code a lookup table in the form of a constant array for use ... If your arrrays (or any other type data members) are nonstatic, ... But arrays cannot be used in a ctor init-list, ... The definitions (and initializers) must appear ...
    (alt.comp.lang.learn.c-cpp)
  • RE: move data between list boxes
    ... >box using arrays. ... >be written to the database. ... >> I have a db with a Members table and a committee table ... >> committee list box using buttons as the wizard does. ...
    (microsoft.public.access.formscoding)
  • Re: Logic C++ error. Why?
    ... In effect, both these data members are self documenting, ... that I originally did use const ... to be compatible with STL containers? ... Chris Val ...
    (alt.comp.lang.learn.c-cpp)
  • RE: move data between list boxes
    ... I am not sure if I understand working with arrays or ... before comitting, my idea is when a name is selected and ... I searched the Access help files and couldn't find any ... >> I have a db with a Members table and a committee table ...
    (microsoft.public.access.formscoding)