When I do compile of my C++ program, I get this error, basically telling me that count has been declared elsewhere.
Where is the connection to the 'stl_algo.h' where it was also declared?
I am running it on linux FC2.
g++ prog3-02.cpp -o prog3-02
prog3-02.cpp: In function `int main()':
prog3-02.cpp:20: error: use of `count' is ambiguous
prog3-02.cpp:11: error: first declared as `int count' here
/usr/include/c++/3.3.3/bits/stl_algo.h:390: error: also declared as `typename
std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
_InputIter, const _Tp&)' here
prog3-02.cpp: In function `void func1()':
prog3-02.cpp:28: error: use of `count' is ambiguous
prog3-02.cpp:11: error: first declared as `int count' here
/usr/include/c++/3.3.3/bits/stl_algo.h:390: error: also declared as `typename
std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
_InputIter, const _Tp&)' here
Here is my program. If I change the references to count to something like countt, it works ok. According to my documentation, count is not a reserved word.
Here is the version.
RPM version 4.3.1
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL
My program.
/* Program #3-02 Global Variables
*/
#include <iostream>
using namespace std;
void func1();
void func2();
int count; // this a global variable
int main()
{
int i; // this is a local variable
for(i=0; i<10; i++)
{
count = i * 2;
func1();
}
return 0;
}
void func1()
{
cout << "count: " << count; // access global count
cout << '\n'; // newline
func2();
}
void func2()
{
int count; //local variable for this function only.
for(count=0; count<3; count++) cout << '.';
}
Kent (the worrier)
Where is the connection to the 'stl_algo.h' where it was also declared?
I am running it on linux FC2.
g++ prog3-02.cpp -o prog3-02
prog3-02.cpp: In function `int main()':
prog3-02.cpp:20: error: use of `count' is ambiguous
prog3-02.cpp:11: error: first declared as `int count' here
/usr/include/c++/3.3.3/bits/stl_algo.h:390: error: also declared as `typename
std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
_InputIter, const _Tp&)' here
prog3-02.cpp: In function `void func1()':
prog3-02.cpp:28: error: use of `count' is ambiguous
prog3-02.cpp:11: error: first declared as `int count' here
/usr/include/c++/3.3.3/bits/stl_algo.h:390: error: also declared as `typename
std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
_InputIter, const _Tp&)' here
Here is my program. If I change the references to count to something like countt, it works ok. According to my documentation, count is not a reserved word.
Here is the version.
RPM version 4.3.1
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL
My program.
/* Program #3-02 Global Variables
*/
#include <iostream>
using namespace std;
void func1();
void func2();
int count; // this a global variable
int main()
{
int i; // this is a local variable
for(i=0; i<10; i++)
{
count = i * 2;
func1();
}
return 0;
}
void func1()
{
cout << "count: " << count; // access global count
cout << '\n'; // newline
func2();
}
void func2()
{
int count; //local variable for this function only.
for(count=0; count<3; count++) cout << '.';
}
Kent (the worrier)