Why do i have run time error?

Hello everyone. I wrote the following code where i pass by reference a class object in a friend function.Tha function just pass a value to a variable of the class object and return this variable.The compiler doesn't return any erors or warnings.

#include<iostream>
using namespace std;

class salami
{
int *a;
friend int foo(salami&);
};

int foo(salami& salam)
{

*salam.a=5;
return (*salam.a);
};



int main()
{
salami aeros;
cout<<"foo(aeros)"<<foo(aeros)<<endl;


return 0;
}

Any sugestions please?
The member "a" of "aeros" is never set to point anywhere, so it is pointing to a random place in memory, which you try to set to five.
thanks mate!
Topic archived. No new replies allowed.