# problem with writing a vector whose elements are a function

Page 1 of 1

## 0 Replies - 227 Views - Last Post: 26 February 2013 - 12:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=313559&amp;s=fb27d3c2b01ead3a0558043cd53204ac&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 richardm1985

Reputation: 4
• 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

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}