I\'m new to programming and have been happily working my way through C++ A Beginner\'s Guide (which I\'m thoroughly enjoying!). However, I\'ve come across a bit of
count
is defined in both your code and by the Standard Library (in the std namespace). Your use of using namespace std;
to drag the entire Standard namespace into the global namespace creates an ambiguity. You should do at least one of the following:
using namespace
std from the global namespace; either use the namespace within your functions, or use just the names you need, or qualify all the standard names when you use them
carefully choose your own names to avoid conflicts with standard namescount
to *something else to avoid ambiguity.count
, writing ::count
.distance
.
I'm guessing this is close to the error you get:
In function 'int main()':
Line 13: error: reference to 'count' is ambiguous
compilation terminated due to -Wfatal-errors.
Using the namespace std
makes count
refer to std::count
which is an algorithm in the standard library.
http://www.cplusplus.com/reference/algorithm/count/