How to make a function use objects outside of function they are declared in

I just wanted to know how you retrieve object values outside of the function they are declared in, like in my project I have a function outside of main and want to use objects declared in main.
maybe pointer could help you?
I think seeing code helps with suggestions :)
parameters?


void function(object &p)
{
p.value = 3;
//p is o from main in this sample....
//and because its a reference, it will modify o if you change p here.
}


int main()
{
object o;
function(o);
}

I was assuming this would be a universal thing, so I didn't think of adding code, but I'll add whats needed.

int main()
{
int equippeditemID;
long PlayerLevel = 1;
int XP;
int strength = 0;
int numofattackonweapon = 0;
int wandabilityID;
int ammo = 10;
//Weapons, melee
swords TrainingSword;
TrainingSword.setSwordDamage(strength, 10);
TrainingSword.setSwordDurability(50, numofattackonweapon);
TrainingSword.setSwordLength(2);
TrainingSword.setItemID(1);
swords ShortSword;
ShortSword.setSwordDamage(strength, 15);
ShortSword.setSwordDurability(100, numofattackonweapon);
ShortSword.setSwordLength(1);
ShortSword.setItemID(2);
swords LongSword;
LongSword.setSwordDamage(strength, 18);
LongSword.setSwordDurability(150, numofattackonweapon);
LongSword.setSwordLength(3);
LongSword.setItemID(3);
swords ArcticRapier;
ArcticRapier.setSwordDamage(strength, 20);
ArcticRapier.setSwordDurability(200, numofattackonweapon);
ArcticRapier.setSwordLength(3);
ArcticRapier.setItemID(4);
swords GreatBlade;
GreatBlade.setSwordDamage(strength, 25);
GreatBlade.setSwordDurability(300, numofattackonweapon/2);
GreatBlade.setSwordLength(4);
GreatBlade.setItemID(5);
}
(again, that's just the objects I need, I'm retrieving the item ID's)
void knight_check_equip()
{
std::vector<int> knightIDs = { TrainingSword.getItemID, ShortSword.getItemID, LongSword.getItemID, ArcticRapier.getItemID, GreatBlade.getItemID };
}
I'm trying to get their values into that function and I'm lost as to what to do.
Topic archived. No new replies allowed.