| | |
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 application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






