473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

accessing a hidden variable

Hi all,

is there a way to access a variable that is hidden by a new variable with
the same name in a nested block like this:
void doSomething()
{
int x = 5;
{
std::string x = doIntFunctionWithX(x);
}
}

you might wonder why I just don't rename the nested 'x'. Well, the code is
generated and it would be easy if I could keep the save variable name
('context' in my situation).

TIA,

Corno

Nov 30 '05 #1
4 2106
On 2005-11-30, Corno <Corno@dds%FAKE%.nl> wrote:
Hi all,

is there a way to access a variable that is hidden by a new variable with
the same name in a nested block like this:
void doSomething()
{
int x = 5;
{
std::string x = doIntFunctionWithX(x);
}
}

you might wonder why I just don't rename the nested 'x'. Well,
the code is generated and it would be easy if I could keep the
save variable name ('context' in my situation).


If you had a pointer or a reference to the outer x you'd be OK.

--
Neil Cerutti
Nov 30 '05 #2

"Neil Cerutti" <le*******@email.com> wrote in message
news:sl**********************@FIAD06.norwich.edu.. .
On 2005-11-30, Corno <Corno@dds%FAKE%.nl> wrote:
Hi all,

is there a way to access a variable that is hidden by a new variable with
the same name in a nested block like this:
void doSomething()
{
int x = 5;
{
std::string x = doIntFunctionWithX(x);
}
}

you might wonder why I just don't rename the nested 'x'. Well,
the code is generated and it would be easy if I could keep the
save variable name ('context' in my situation).


If you had a pointer or a reference to the outer x you'd be OK.

That's what I'm doing right now with a temp declaration just before the new
'x' declaration, but I was hoping for a more elegant (less ugly) solution.
Nov 30 '05 #3
Corno wrote:
void doSomething()
{
int x = 5;
{
std::string x = doIntFunctionWithX(x);
}
}

you might wonder why I just don't rename the nested 'x'. Well, the code is
generated and it would be easy if I could keep the save variable name
('context' in my situation).


What kind of stupid code generator creates code with potential conflicts
like this??? Really, I want to know, so I can avoid it.
Nov 30 '05 #4

"Corno" <Corno@dds%FAKE%.nl> wrote in message
news:dm**********@azure.qinip.net...
Hi all,

is there a way to access a variable that is hidden by a new variable with
the same name in a nested block like this:
void doSomething()
{
int x = 5;
{
std::string x = doIntFunctionWithX(x);
}
}

you might wonder why I just don't rename the nested 'x'. Well, the code is
generated and it would be easy if I could keep the save variable name
('context' in my situation).

If the code is generated for you, then what kind of solution could we
possibly provide? Any solution would mean a code change, which you'd have
to to each time you re-generate the code, right? So the best solution would
be to rename one of those variables.

You might also check with whatever tool is generating that code. Is it from
some kind of diagram? Maybe you can change something in the diagram (or in
the tool settings) which will cause the tool to generate specific names
instead of the totally meaningless x (and other identifiers) shown here?

-Howard

Nov 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Craig Anderson | last post by:
Can anyone tell me the best way to access a hidden object in a form? I could use a hard-coded index to the elements of the form, but it's too easy to add something before the hidden object and mess...
5
by: ms_chika | last post by:
Hi to all, I have this problem in xsl wherein i want to access a variable in javascript and use it my xsl. How would i access or use a javscript variable in my xsl file? Please help. ...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
19
by: k.karthikit | last post by:
Hello all, In some hidden variable (<input type="hidden" name="hiddenId" value="test" /> ,i stored some value.I accessed the value "test" using var id = document.getElementById( 'hiddenId' );...
0
by: Ben | last post by:
Hi All, I have a web app which uses Frames, frame 1 with search criteria(1.aspx) and frame 2 with results(2.aspx). Frame2 in turn posts to a servlet(action="servlet URL") and the report parameters...
2
by: Zuhaib Hyder | last post by:
please remove double quote error in accessing javascript variable in c# , Page.RegisterStartupScript("MyScript", "<script language=javascript> var thumb = null;thumb =...
1
by: Jeff User | last post by:
hi all Using C#, .NET1.1. I need to pass a string of text to the final html output and then capture it with java script on the client side. I found that I can place my string in and then...
2
Frinavale
by: Frinavale | last post by:
Hi! I am dynamically generating external .js JavaScript resources to be used with a Tab control I created (using VB.NET). Originally, the JavaScript was written directly into the <head> of the...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.