Scope resolution operator

Discussion in 'C++' started by Shan, Jun 2, 2008.

  1. Shan

    Shan Guest

    In the following code:

    func()
    {
    int SmeVar;
    {
    int SmeVar;
    //Here I want to use SmeVar defined in the outer block how
    can I do that ?
    }
    }
    Shan, Jun 2, 2008
    #1
    1. Advertising

  2. Shan

    Jerry Coffin Guest

    In article <f7d55779-b634-4973-bd5d-
    >,
    says...
    > In the following code:
    >
    > func()
    > {
    > int SmeVar;
    > {
    > int SmeVar;
    > //Here I want to use SmeVar defined in the outer block how
    > can I do that ?
    > }
    > }


    It's not possible unless the namespace in which SmeVar is located has a
    name, which it doesn't in this case.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Jun 2, 2008
    #2
    1. Advertising

  3. Shan

    Stefan Naewe Guest

    Stefan Naewe, Jun 2, 2008
    #3
  4. Shan

    Shan Guest

    On Jun 2, 5:15 pm, Stefan Naewe <> wrote:
    > On 6/2/2008 1:46 PM, Shan wrote:> In the following code:
    >
    > > func()
    > > {
    > > int SmeVar;
    > > {

    >
    > int& outer_SmeVar = SmeVar;
    >
    > > int SmeVar;
    > > //Here I want to use SmeVar defined in the outer block how
    > > can I do that ?
    > > }
    > > }

    >
    > S.
    >
    > --
    > Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    > Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    > Plain text mails only, please http://www.expita.com/nomime.html

    Hi,
    Thanks for the reply, can you suggest any way of doing this using
    scope resolution operator?
    Shan, Jun 2, 2008
    #4
  5. Shan

    Stefan Naewe Guest

    On 6/2/2008 2:24 PM, Shan wrote:
    > On Jun 2, 5:15 pm, Stefan Naewe <> wrote:
    >> On 6/2/2008 1:46 PM, Shan wrote:> In the following code:
    >>
    >>> func()
    >>> {
    >>> int SmeVar;
    >>> {

    >> int& outer_SmeVar = SmeVar;
    >>
    >>> int SmeVar;
    >>> //Here I want to use SmeVar defined in the outer block how
    >>> can I do that ?
    >>> }
    >>> }

    >> S.
    >>

    > Hi,
    > Thanks for the reply, can you suggest any way of doing this using
    > scope resolution operator?


    No.
    Read what Jerry said. You need a named scope.

    S.
    --
    Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    Plain text mails only, please http://www.expita.com/nomime.html
    Stefan Naewe, Jun 2, 2008
    #5
  6. Shan

    Jim Langston Guest

    Shan wrote:
    > On Jun 2, 5:15 pm, Stefan Naewe <> wrote:
    >> On 6/2/2008 1:46 PM, Shan wrote:> In the following code:
    >>
    >>> func()
    >>> {
    >>> int SmeVar;
    >>> {

    >>
    >> int& outer_SmeVar = SmeVar;
    >>
    >>> int SmeVar;
    >>> //Here I want to use SmeVar defined in the outer block how
    >>> can I do that ?
    >>> }
    >>> }

    >>
    >> S.
    >>
    >> --
    >> Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    >> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    >> Plain text mails only, please http://www.expita.com/nomime.html

    > Hi,
    > Thanks for the reply, can you suggest any way of doing this using
    > scope resolution operator?


    Sure. Give one of the variables a different name.

    --
    Jim Langston
    Jim Langston, Jun 2, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. exits funnel

    Scope Resolution Operator

    exits funnel, Dec 12, 2003, in forum: C++
    Replies:
    5
    Views:
    539
    exits funnel
    Dec 13, 2003
  2. richard pickworth

    scope resolution operator

    richard pickworth, Jun 5, 2005, in forum: C++
    Replies:
    3
    Views:
    588
    richard pickworth
    Aug 8, 2005
  3. sushant

    scope resolution operator???????

    sushant, Jan 7, 2005, in forum: C Programming
    Replies:
    16
    Views:
    917
    Lawrence Kirby
    Jan 10, 2005
  4. Jack
    Replies:
    6
    Views:
    545
  5. dwaach
    Replies:
    1
    Views:
    384
    Victor Bazarov
    Jul 6, 2006
Loading...

Share This Page