Employees * e;
e = company.maxSalary();
if (e) e-%26gt;showEmployee();
else cout %26lt;%26lt;';There is no employee'; ;
What should maxSalary() { } return in order for if (e) to be false and use the ';else'; ???How Do I return A False Pointer In C++?
you return a NULL which is defined as:
#define NULL ((void*)0)
you could just return 0 if type checking isn't a problem, the if will evaluate as false if a 0 or NULL are used which will cause the else to be ran.How Do I return A False Pointer In C++?
Again C++ pointer just has two value:
1.NULL (this pointer points to nothing)
2.(not NULL) this pointer points to somethings.
If there is no maxSalary() so just return to it a NULL value.
Let it return NULL pointer when there is no employee. You may have to change if clause to if(e!=NULL). If NULL is returned then else part will execute.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment