Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. struct Data {
  6.     int iValue;
  7.     float fValue;
  8.     std::string sValue;
  9. };
  10.  
  11. struct Parameter {
  12.     std::vector<Data> data;
  13. };
  14.  
  15. void func1(const Parameter& p) {
  16.     for (int i = 0; i < p.data.size(); ++i)
  17.         std::cout << "func1 param " << i << ": " << p.data[i].iValue << ", "
  18.         << p.data[i].fValue << ", " << p.data[i].sValue << std::endl;
  19. }
  20.  
  21. void func2(const Parameter& p) {
  22.     for (int i = 0; i < p.data.size(); ++i)
  23.         std::cout << "func2 param " << i << ": " << p.data[i].iValue << ", "
  24.         << p.data[i].fValue << ", " << p.data[i].sValue << std::endl;
  25. }
  26.  
  27. void func3(const Parameter& p) {
  28.     for (int i = 0; i < p.data.size(); ++i)
  29.         std::cout << "func3 param " << i << ": " << p.data[i].iValue << ", "
  30.         << p.data[i].fValue << ", " << p.data[i].sValue << std::endl;
  31. }
  32.  
  33. void func4(const Parameter& p) {
  34.     for (int i = 0; i < p.data.size(); ++i)
  35.         std::cout << "func4 param " << i << ": " << p.data[i].iValue << ", "
  36.         << p.data[i].fValue << ", " << p.data[i].sValue << std::endl;
  37. }
  38.  
  39. int main(int argc, char** argv)
  40. {
  41.     void(*pFunctions[4])(const Parameter& p) = { func1, func2, func3, func4 };
  42.     Parameter p;
  43.     p.data.push_back({ 5, 0, "" });
  44.     p.data.push_back({ 0, 3.14, "" });
  45.     p.data.push_back({ 0, 0, "Merkkijono" });
  46.     (*pFunctions[0])(p);
  47.     (*pFunctions[1])(p);
  48.     p.data[1] = { 0, 3.14 * 3, "" };
  49.     p.data.push_back({ 666, 6.66, "666" });
  50.     (*pFunctions[2])(p);
  51.  
  52.     return EXIT_SUCCESS;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement