i have a class called Employee and a method in that class called display(). When that method is called it displays a first name and a last name.

In my int main() i have...

int main()
{
Employee emp;
Employee* ptr;

return 0 ;
}

I was wondering if there were a way to have the pointer point to emp and then use the pointer to display emp as opposed to simply saying...

emp.display();

if this is possible how would i do it?

Thanks for the help

Well yes its possible, but why would you want to do it? Unless, of course you are passing a pointer to another function.

Employee emp;
Employee* ptr = &emp;
ptr->display();

Well yes its possible, but why would you want to do it?

I was just trying to figure out how powerful or useful pointers are because they just seem worthless to me...thanks for your help though.

Edited 3 Years Ago by diafol: fixed formatting

one purpose of pointers to to allocate an array of something because the size is not known until the program is run. Employee* empArray = new Employee[NumberEmployees]; Another purpose: creating a linked list of Employee classes. Admittedly most c++ programmers would using c++ container classes such as vector or dqueue.

I was just trying to figure out how powerful or useful pointers are because they just seem worthless to me...thanks for your help though.

Then you simply don't know enough of the language yet. The knowledge and understanding will come. You don't need to rush it yet.

This article has been dead for over six months. Start a new discussion instead.