Solved

Access Golbal var ?

Posted on 2000-04-11
3
174 Views
Last Modified: 2010-04-02
How can I access a global variable from a function which has same name as local variable in c++?
0
Comment
Question by:rahul_asanikar
3 Comments
 

Author Comment

by:rahul_asanikar
ID: 2556746
Adjusted points to 20
0
 
LVL 1

Accepted Solution

by:
Dhrubajyoti earned 20 total points
ID: 2710574
use scope resolution operator.
eg try this
  my global variable name is test;

MyFunc()
{
   int test;
   ::test=5;//this will refer to
           //global variable
   test=7;//this will refer
            //    to local varable
   }
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2744007
or use namespace...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now