Solved

Access Golbal var ?

Posted on 2000-04-11
3
178 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

792 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