473,385 Members | 1,930 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,385 software developers and data experts.

Variables in (and out) of namespaces

Say I have the code in a program below:

namespace c_name
{
int j;
}

int main(int argc, char* argv[])
{
using namespace std;
int j;
cout<<"Hello, World!"<<endl;
using namespace c_name;
j = 5;
}

I was wondering how I could access j (the not the one in c_name).
Any tips?
Kieran
Jul 22 '05 #1
4 1009
"K Campbell" <ki****@cyrocom.co.uk> wrote...
Say I have the code in a program below:

namespace c_name
{
int j;
}

int main(int argc, char* argv[])
{
using namespace std;
int j;
cout<<"Hello, World!"<<endl;
using namespace c_name;
j = 5;
}

I was wondering how I could access j (the not the one in c_name).
Any tips?


There is no way. A tip: don't use 'using', use 'c_name::'.

V
Jul 22 '05 #2
"K Campbell" <ki****@cyrocom.co.uk> wrote in message
namespace c_name
{
int j;
}

int main(int argc, char* argv[])
{
using namespace std;
int j;
cout<<"Hello, World!"<<endl;
using namespace c_name;
j = 5;
}

I was wondering how I could access j (the not the one in c_name).
Any tips?


Does ::j work?
Jul 22 '05 #3
"Siemel Naran" <Si*********@REMOVE.att.net> wrote...
"K Campbell" <ki****@cyrocom.co.uk> wrote in message
namespace c_name
{
int j;
}

int main(int argc, char* argv[])
{
using namespace std;
int j;
cout<<"Hello, World!"<<endl;
using namespace c_name;
j = 5;
}

I was wondering how I could access j (the not the one in c_name).
Any tips?


Does ::j work?


Why would it? There is no j in the global namespace.

V
Jul 22 '05 #4
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:_vvsd.716685
"Siemel Naran" <Si*********@REMOVE.att.net> wrote...

int main(int argc, char* argv[])
{
using namespace std;
int j;
cout<<"Hello, World!"<<endl;
using namespace c_name;
j = 5;
}

I was wondering how I could access j (the not the one in c_name).
Any tips?


Does ::j work?


Why would it? There is no j in the global namespace.


Yes, I tried it and it gives a compile error.
Jul 22 '05 #5

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

Similar topics

181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
16
by: Eric | last post by:
I have a static class member variable as follows: struct A { static void Set (int i) { v = i; } static int& Get () { return v; } static int v; }; int A::v; // define A::v in the cpp file
3
by: Sehcra | last post by:
Hi, I'm trying to figure out if what I'm doing makes any sense. I created a namespace that contains some functions as well as some constants. Because these variables are constant, I have no...
9
by: ur8x | last post by:
Hi, I was wondering if there is a difference between declaring a static variable outside of the method as oppose to declaring it as a local variable? Thanks.
8
by: newbie | last post by:
Hello, I have questions about global variables in OOP (in general) and Python (in specific). I understand (I think) that global variables are generally not a good idea. However, if there are...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.