| | |
pointers and classes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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...
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...
if this is possible how would i do it?
Thanks for the help
In my int main() i have...
C++ Syntax (Toggle Plain Text)
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...
C++ Syntax (Toggle Plain Text)
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.
C++ Syntax (Toggle Plain Text)
Employee emp; Employee* ptr = &emp; ptr->display();
Last edited by Ancient Dragon; Dec 2nd, 2007 at 8:55 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
one purpose of pointers to to allocate an array of something because the size is not known until the program is run.
Another purpose: creating a linked list of Employee classes. Admittedly most c++ programmers would using c++ container classes such as vector or dqueue.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Purpose of Pointers? (C++)
- Help with pointers and classes (C++)
- pointers to windows forms (C)
- Classes and using Static member functions to subtotal/total (C++)
- Converting Struct to class lost with pointers (C++)
- storing references to classes (C++)
- conversion type (C++)
Other Threads in the C++ Forum
- Previous Thread: c++ letter coding
- Next Thread: Just a lil fun
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






