What are the advantages of having pointers to functions again ... and what kind of set up do they need?
What are the advantages of having pointers to functions again ... and what kind of set up do they need?
Pointers to functions allow you to defer deciding what function is called until runtime. Their syntax is generally messy, and virtual functions do the same thing. I'd recommend learning inheritance and polymorphism rather than function pointers.
Actually inheretence and polymorphism are why I ask. They were both in this "week" and I'm reading the review for the week and this code is what is throwing me off.
It's mostly the astericks that I'm tripping over ... if you need the function definitions I can edit this and put them on.Code:class PartsList { public: PartsList(); ~PartsList(); // needs copy constructor and operator equals Part* Find(int & position, int PartNumber) const; int GetCount() const { return itsCount; } Part* GetFirst() const; void Insert(Part *); void Iterate() const; Part* operator[](int) const; private: PartNode * pHead; int itsCount; };
Those aren't function pointers.. just standard pointers. Is it that a function returning a pointer is confusing you?
SilentStrike is correct, Those function return pointers to obj's.
Function pointers look like -
Code:void foo(void){ printf("Foo\n"); } int main(void){ void (*fptr)(void); // fptr can point to any function that is // sent (void) and receives (void) fptr = foo; // make the function pointer point to foo (*fptr)(); // call whatever fptr is pointing to and send ()
I guess so ... I didn't even realze that was a function returning a pointer ... it's so much clearer now ... thank you