delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/09/18/10:44:02

From: MCheu <mpcheu AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help in my codes.
Message-ID: <3voboug43iagagl91bk5o4buuu2is8fava@4ax.com>
References: <am3jv2$vbr$1 AT reader01 DOT singnet DOT com DOT sg>
X-Newsreader: Forte Agent 1.92/32.572
MIME-Version: 1.0
Lines: 60
Date: Mon, 16 Sep 2002 10:11:02 -0400
NNTP-Posting-Host: 209.188.65.153
X-Trace: localhost 1032185468 209.188.65.153 (Mon, 16 Sep 2002 08:11:08 MDT)
NNTP-Posting-Date: Mon, 16 Sep 2002 08:11:08 MDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 16 Sep 2002 11:48:28 +0800, "Kim Seng" <Query AT singnet DOT com DOT sg>
wrote:

>Hi guys,
>
>Would need your help in these data codes? I tried to complie it in DJGPP bit
>I was faced with some errors as below:
>
>------------------Cut here-------------------
>C:\DJGPP\mystuff>gxx program13.cc -o program13.exe -lm
>program13.cc: In function `int main()':
>program13.cc:14: use of `count' is ambiguous
>program13.cc:7:   first declared as `int count' here
>c:/djgpp/lang/cxx-v3/bits/stl_algo.h:320:   also declared as `typename
>   std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
>   _InputIter, const _Tp&)' here
>program13.cc: In function `void func1()':
>program13.cc:23: use of `count' is ambiguous
>program13.cc:7:   first declared as `int count' here
>c:/djgpp/lang/cxx-v3/bits/stl_algo.h:320:   also declared as `typename
>   std::iterator_traits<_Iterator>::difference_type std::count(_InputIter,
>   _InputIter, const _Tp&)' here
>--------------Cut here---------------------
>
>Thanks in advance.
>
>

Don't use attachments.   Quote the code in the text body using cut &
paste.   Most people won't read attachments.

as to your code:

> int count; // This is a global variable
>
> void func2()
> {
> int count; // this is a local variable
>
> for(count=0; count<3; count++) cout << '.';
>
> }

This is the problem area.   You've even commented the reason for the
problem.   

You first declare a global variable named count.   This variable is
visible to all functions within this program, so its scope encompasses
the scope of func2() as well.   When you declared the local count,
there already exists a previously declared variable within scope named
count.

In func2(), either make use of the global variable count (already
declared) or use another name for that local variable.


-----------
Thanks

MCheu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019