By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,140 Members | 1,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,140 IT Pros & Developers. It's quick & easy.

gcc compile error about vector

P: n/a
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.

Nov 30 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hu**********@gmail.com wrote:

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.


Do you have a more specific error message then that?

--
Karl Heinz Buchegger
kb******@gascad.at
Nov 30 '05 #2

P: n/a
Karl Heinz Buchegger wrote:
Hu**********@gmail.com wrote:

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.


Do you have a more specific error message then that?

--
Karl Heinz Buchegger
kb******@gascad.at


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

Nov 30 '05 #3

P: n/a
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

Nov 30 '05 #4

P: n/a
Hu**********@gmail.com writes:
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.


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
Nov 30 '05 #5

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

Dec 1 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.