I have one clarification,
class Foo
{
}
main()
{
Foo obj; //1
method(obj);
method1(&obj);
Foo* obj1;
method2(&obj1); //4
}
void method(Foo objfoo) //2
{
}
void method1(Foo* objfoo) //3
{
}
void method2(Foo* & objfoo){}
Q1. Will it allocates objects inside main stack frame ?
Q2. Will it create one more copy of Foo inside method stack frame ?
Q3. Will it point same object exists in obj present in main method ?
Q4. What this indicates ? need explanation ?
These are ordered by the Q1, Q2, etc., not the order they appear in the question.
obj1tomethod2.Aside: the call to
method2mentioned in Q4 won’t actually work. Sinceobj1is defined as a pointer to aFoo, andmethod2takes a reference to a pointer to a Foo, you would not need to (explicitly) take the address of the point to make the call. Doing so creates a pointer to a pointer, wheremethod2needs a reference to a pointer. Usingmethod2(obj1);would be at least syntactically correct (open to question whether it will really work correctly though).