S
sg
In the below code
when we are passing by value in the function
SomeFunc(CDanglingPointers x) why the local object is not created?
class CDanglingPointers
{
public:
int *ptr;
CDanglingPointers(int i)
{
ptr = new int(i);
}
~CDanglingPointers()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(CDanglingPointers x) => when we are passing by value why
the local object is not created?
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
CDanglingPointers s1 = 10;
SomeFunc(s1);
s1.PrintVal();
}
when we are passing by value in the function
SomeFunc(CDanglingPointers x) why the local object is not created?
class CDanglingPointers
{
public:
int *ptr;
CDanglingPointers(int i)
{
ptr = new int(i);
}
~CDanglingPointers()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(CDanglingPointers x) => when we are passing by value why
the local object is not created?
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
CDanglingPointers s1 = 10;
SomeFunc(s1);
s1.PrintVal();
}