Value which is changed inside a function will not be reflected after call. So you are setting b as pointer to class a but this value will not retain after function call in main().
On Thu, Jul 21, 2011 at 5:40 PM, Saurabh <[email protected]> wrote: > Can any one explain why the following program not giving the correct > output. > > #include <iostream> > using namespace std; > class a > { > int x; > > public: > void set(int y) > { > x=y; > } > int get() > { > return x; > } > > }; > void f(a * b) > { > b = new a(); > b->set(5); > } > int main() > { > a *a1; > f(a1); > cout<<"x = "<<a1->get(); > return 0; > } > > > > -- > Regards > Saurabh > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Dinesh Bansal The Law of Win says, "Let's not do it your way or my way; let's do it the best way." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
