0 Replies - 140 Views - Last Post: 26 February 2013 - 12:11 AM Rate Topic: -----

#1 richardm1985  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 31
  • Joined: 28-November 12

problem with writing a vector whose elements are a function

Posted 26 February 2013 - 12:11 AM

Ok so here is the exercise I have (I only need help with the first, I am hoping to be able to do the rest on my own):

Exercise 6.54: Write a declaration for a function that takes two int parameters and
returns an int, and declare a vector whose elements have this function pointer type.

Exercise 6.55: Write four functions that add, subtract, multiply, and divide two int
values. Store pointers to these values in your vector from the previous exercise.

Exercise 6.56: Call each element in the vector and print their result.

What I have so far

typedef int (*pf)(int a, int B)/>/>;
vector<pf> ivec;


How do I write the definition for the function??

Is this correct?

int sum(int a, int B)/>/>/>
{
	return(5 + 6);
}


Do I use ivec.push_back(pf OR sum)??? I really have no idea

please ignore the "/>" near the function declarations, somehow got added into my code when posting.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1