This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Help : Is this a namespace collision ??


 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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]