Help : Is this a namespace collision ??
m.
michal017@centrum.sk
Sun Nov 24 22:43:00 GMT 2002
Just read what the compiler says..
>NewHandler.cpp:12: first declared as `int count' here
>/usr/include/c++/3.2.1/bits/stl_algo.h:390: also declared as `
> std::iterator_traits<_Iterator>::difference_type
>std::count(_InputIter,
> _InputIter, const _Tp&)' here
There's a function std::count() declared in bits/stl_algo.h..
m.
On 25 Nov 2002 06:55:52 +0100
Christian POKAM <chrispot@cs.tu-berlin.de> wrote:
> Why is the Compilation of NewHandler.cpp complaining about
> the ambigous use of "count" ??
> Thank you
>
>//NewHandler.cpp
>// From Thinking in C++, 2nd Edition
>// Available at http://www.BruceEckel.com
>// (c) Bruce Eckel 2000
>// Copyright notice in Copyright.txt
>// Changing the new-handler
>#include <iostream>
>#include <cstdlib>
>#include <new>
>using namespace std;
>
>int count = 0;
>
>void out_of_memory() {
> cerr << "memory exhausted after " << count
> << " allocations!" << endl;
> exit(1);
>}
>
>int main() {
> set_new_handler(out_of_memory);
> while(1) {
> count++;
> new int[1000]; // Exhausts memory
> }
>} //
>
>
>gcc version 3.2.1 ; linux kernel 2.4.19 ; glibc 2.3.1
>gcc output:
>
>NewHandler.cpp: In function `void out_of_memory()':
>NewHandler.cpp:16: use of `count' is ambiguous
>NewHandler.cpp:12: first declared as `int count' here
>/usr/include/c++/3.2.1/bits/stl_algo.h:390: also declared as `
> std::iterator_traits<_Iterator>::difference_type
>std::count(_InputIter,
> _InputIter, const _Tp&)' here
>NewHandler.cpp: In function `int main()':
>NewHandler.cpp:23: use of `count' is ambiguous
>NewHandler.cpp:12: first declared as `int count' here
>/usr/include/c++/3.2.1/bits/stl_algo.h:390: also declared as `
> std::iterator_traits<_Iterator>::difference_type
>std::count(_InputIter,
> _InputIter, const _Tp&)' here
>
>
>--
>Christian POKAM <chrispot@cs.tu-berlin.de>
>
More information about the Gcc-help
mailing list