Quantcast

Maximum PC

It is currently Fri Apr 18, 2014 4:16 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: CPP scopes question
PostPosted: Mon Jan 18, 2010 9:21 am 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
I have a variable in global scope and need to access in a non-global scope, how do i do this?


Top
  Profile  
 
 Post subject: Re: CPP scopes question
PostPosted: Mon Jan 18, 2010 9:53 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Dwood15 wrote:
I have a variable in global scope and need to access in a non-global scope, how do i do this?
Isn't that the whole point of Global variables?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 10:10 am 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
Here's the thing, I have an inline file called key_inputs

with the namespaces

Example { Key_Input{};};

My Variable(say, int examp) is in another file called example.cpp, if I try changing examp in a function inside of Key_Input, Visual studio tells me examp is an undeclared identifier.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 10:56 am 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
Nevermind, I found my answer here: http://www.learncpp.com/cpp-tutorial/42 ... variables/

Thanks for nothing my two stupid text books on c++ *twitch*


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 10:58 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Sun May 22, 2005 8:28 am
Posts: 3673
Location: The Blue Nowhere
Your explanation of the situation is terrible, explain yourself better.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 11:00 am 
Northwood
Northwood
User avatar

Joined: Sun Jul 15, 2007 6:37 pm
Posts: 2261
Location: No. 1 Thread Killer
Lodis4 wrote:
Your explanation of the situation is terrible, explain yourself better.


Using a global variable across multiple files?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 11:03 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Sun May 22, 2005 8:28 am
Posts: 3673
Location: The Blue Nowhere
The program could care less about the files as long as they are part of the program solution (read: #include) statements. Now you have twice explained yourself poorly.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Jan 18, 2010 11:20 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24218
Location: Granite Heaven
Don't be a dick.

That's my job.

:D


Top
  Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2010 11:23 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Lodis4 wrote:
The program could care less about the files as long as they are part of the program solution (read: #include) statements.


That isn't always an option. What if the global variable was in a shared library that didn't include the source code?

http://www.iu.hio.no/~mark/CTutorial/CT ... d%20extern

And yes, Dwood15 could have done a better job of explaining himself.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group