![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Sharing Variables in C++ from a main.h within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I need some help! I converted rpg paradise from C to C++ and then I got 'multiple definition' errors. I ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() |
I need some help! I converted rpg paradise from C to C++ and then I got 'multiple definition' errors. I tried changing the vars to 'static' vars but then they don't share the var, they just each get their own of that var.
So how do I declare a var that will be shared amoung different c++ files from a header file? So say main.h had this Code:
int i; Code:
i = 211;
if(i == GetVar()){ printf("This is what I want."); }
Code:
int GetVar()
{
return i;
}
-= Double Post =- I found the solution, I had to use extern, mods can delete this thread Last edited by pspballer07; 06-01-2007 at 11:59 AM.. Reason: Automerged Doublepost |
|
|
|
|
#2 |
![]() |
Code:
extern i = 211;
if(i == GetVar()){ printf("This is what I want."); }
__________________
YEAH! [center][COLOR="DimGray"][SIZE="2"][FONT="Times New Roman"]Julius Parishy [[URL="http://jparishy.com"]Homepage[/URL]][/FONT][/COLOR] Affiliates: [url=http://xfacter.jparishy.com/]Xfacter[/url] | [url=http://flatmush.jparishy.com/]Flatmush[/url] | [url=http://yaustar.jparishy.com/]Yaustar[/url] [url=http://jparishy.com/wp/source-code/]Soure Code[/url] [/center] [/size] |
|
|
|
|
#4 |
![]() |
**** off! Stop antagonizing every single person who asks a question!
Why do you make flashers? Do you know you are hated by the entire PSP-Programming community? Do you honestly think you have any right to ask a question? What makes you better than anyone else? Could your damn ego be any bigger? Instead of being an ******* and repeating yourself to the same people with the same question, why don't you go ahead and answer those questions for me? Here, I'll give you a hint on one of them. No one gives a **** what you think or what you say, so you have no right to be saying anything to this kid. I'm telling you right now, we have been wanting to do this for a very long time. We don't want you here. Stop acting like you're the boss.
__________________
YEAH! [center][COLOR="DimGray"][SIZE="2"][FONT="Times New Roman"]Julius Parishy [[URL="http://jparishy.com"]Homepage[/URL]][/FONT][/COLOR] Affiliates: [url=http://xfacter.jparishy.com/]Xfacter[/url] | [url=http://flatmush.jparishy.com/]Flatmush[/url] | [url=http://yaustar.jparishy.com/]Yaustar[/url] [url=http://jparishy.com/wp/source-code/]Soure Code[/url] [/center] [/size] |
|
|
|
|
#5 | |
![]() ![]() ...in a dream...
|
Quote:
![]() Anyways, external variables aren't C++ specific, so going from C to C++ shouldn't have changed anything, nor been necessary. Usual practice is to put: Code:
extern int foo; Code:
#include "foo.h" int foo = 0; Code:
#include "foo.h" Including foo.h in foo.c allows the compiler to check the declaration in foo.h against the corresponding definition in foo.c to ensure that they match.
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
![]() |
| Tags |
| mainh , sharing , variables |
| Thread Tools | |
|
|