0

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

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by WaltP
0

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();
0

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 by diafol: fixed formatting

0

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.

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.