can anyone telll me how to assign a pointer as a default argument for a c++ function. I tried but clouldn't do anything much useful.Please help.
can anyone telll me how to assign a pointer as a default argument for a c++ function. I tried but clouldn't do anything much useful.Please help.
It's just like any other function defaulting. Here is some code illustrating it.
Perhaps you should post code that isn't working for you?Code:#include <iostream> using namespace std; void f(int* g = 0) { if (g != 0) std::cout << *g << std::endl; } int main() { int a=5; int* pA=&a; f(); f(pA); f(&a); return 0; }
You don't need the std:: if you #include namespace std;
Truth is a malleable commodity - Dick Cheney
Yeah, I know.. I just usually don't do the using namespace std thing .