Connecting Tech Pros Worldwide Help | Site Map

gcc compile error about vector

Huang.Antony@gmail.com
Guest
 
Posts: n/a
#1: Nov 30 '05
HI, when I try the following code, I get a compile error with gcc3.3
under mac OS.

int fill;

struct emp{
int f;
};

#include <vector>

void test(void)
{
std::vector<emp> vt;

vt.resize(2);
}

run 'gcc -x c++ -c -o t.o t.cpp'
gcc can't compile that code.

I'd appreciate any help on this issue.

Karl Heinz Buchegger
Guest
 
Posts: n/a
#2: Nov 30 '05

re: gcc compile error about vector


Huang.Antony@gmail.com wrote:[color=blue]
>
> HI, when I try the following code, I get a compile error with gcc3.3
> under mac OS.
>
> int fill;
>
> struct emp{
> int f;
> };
>
> #include <vector>
>
> void test(void)
> {
> std::vector<emp> vt;
>
> vt.resize(2);
> }
>
> run 'gcc -x c++ -c -o t.o t.cpp'
> gcc can't compile that code.
>
> I'd appreciate any help on this issue.[/color]

Do you have a more specific error message then that?

--
Karl Heinz Buchegger
kbuchegg@gascad.at
Huang.Antony@gmail.com
Guest
 
Posts: n/a
#3: Nov 30 '05

re: gcc compile error about vector


Karl Heinz Buchegger wrote:[color=blue]
> Huang.Antony@gmail.com wrote:[color=green]
> >
> > HI, when I try the following code, I get a compile error with gcc3.3
> > under mac OS.
> >
> > int fill;
> >
> > struct emp{
> > int f;
> > };
> >
> > #include <vector>
> >
> > void test(void)
> > {
> > std::vector<emp> vt;
> >
> > vt.resize(2);
> > }
> >
> > run 'gcc -x c++ -c -o t.o t.cpp'
> > gcc can't compile that code.
> >
> > I'd appreciate any help on this issue.[/color]
>
> Do you have a more specific error message then that?
>
> --
> Karl Heinz Buchegger
> kbuchegg@gascad.at[/color]

I get an error saying (amongst other things).
BTW, I compile the code with gcc3.3 under mac OS10.3(Xcode2.x require
above mac OS10.4, I'm afraid of my machine will be slow if I upgrade to
OS10.4).

error: `fill' is not a function,
/usr/include/g++/bits/stl_algobase.h:561: error: conflict with `void
std::fill(char*, char*, const char&)'

best,

Tony

ViralPatel@octon.org.uk
Guest
 
Posts: n/a
#4: Nov 30 '05

re: gcc compile error about vector


This was fixed sometime between 3.2.3 & 3.4.4, in the stl_bvector.h &
stl_deque.h, gcc headers were changed from using "fill..." to
"std::fill...".

The problem looks like it's to do with the way the std::vector template
is instantiated, I think this may be a case of ADL not doing what is
expected. If you instantiate a vector of a type that is declared in the
same namespace as "int fill" then it will work fine! In this case
because you are creating std::vector<emp>, when it looks for "fill"
that is used in std::vector it first looks in the global namespace
(where emp is) and then finds "int fill" and gets confused.

So either you need to upgrade or try something like

#define fill std::fill
#include <vector>
#include <deque>
#undef fill

No guarenties mind you. :)

If you don't want to maintain this in the future then wrap this up so
it is disabled once you switch to a newer compiler, as this does break
with the 3.4.4 I have.

Good luck

Niklas Norrthon
Guest
 
Posts: n/a
#5: Nov 30 '05

re: gcc compile error about vector


Huang.Antony@gmail.com writes:
[color=blue]
> HI, when I try the following code, I get a compile error with gcc3.3
> under mac OS.
>
> int fill;
>
> struct emp{
> int f;
> };
>
> #include <vector>
>
> void test(void)
> {
> std::vector<emp> vt;
>
> vt.resize(2);
> }
>
> run 'gcc -x c++ -c -o t.o t.cpp'
> gcc can't compile that code.
>
> I'd appreciate any help on this issue.[/color]

Then you'll have to supply more information. How do you know that
gcc can't compile the code? Perhaps it gave you an error message
that could contain some useful information.

I compiled the code above without any diagnostics on gcc 3.4.2 and
4.1.0. It even worked with the flags -ansi -pedantic -W -Wall.

/Niklas Norrthon
Chimp
Guest
 
Posts: n/a
#6: Dec 1 '05

re: gcc compile error about vector


There's a more consise explaination here:
http://www.open-std.org/jtc1/sc22/wg...fects.html#225

Closed Thread