Uhh help real quick please...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Uhh help real quick please...

Post by Bludklok »

I might be going crazy but in C++ can't you assign a value to a variable in the global scope?

Code: Select all

int a;
a = 20;

int main()
{
return 0;
}

Either my compiler is being retarded and not letting me do this or I'm losing my mind... or I'm tired. :shock:
Youtube
Website
Current project: Enigma Core
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Uhh help real quick please...

Post by qpHalcy0n »

int a = 20; // This is value assignment and is valid.


int a;
a = 20; // This is an executable piece of code and is NOT valid in the global scope.
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Re: Uhh help real quick please...

Post by Bludklok »

qpHalcy0n wrote:int a = 20; // This is value assignment and is valid.


int a;
a = 20; // This is an executable piece of code and is NOT valid in the global scope.
Thought so...

Such a basic rule too. Just been under a lot of stress lately. :(
Youtube
Website
Current project: Enigma Core
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Uhh help real quick please...

Post by RyanPridgeon »

qpHalcy0n wrote:int a = 20; // This is value assignment and is valid.
Wow, I never realised you could do that in the global scope
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
sparda
Chaos Rift Junior
Chaos Rift Junior
Posts: 291
Joined: Tue Sep 23, 2008 3:54 pm

Re: Uhh help real quick please...

Post by sparda »

int a = 20; // This is value assignment and is valid.
assignment != initialization.

That is why you can initialize:

Code: Select all

int a = 20; // Initialization
And not be able to assign in global scope:

Code: Select all

int a;
a = 20; // assignment
Post Reply