| | |
pointers and classes
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
Views: 1001 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






