Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. struct A { int a; };
  2. struct B { int b; };
  3. struct C { float c; };
  4.  
  5. int main()
  6. {
  7. A a; B b; C c;
  8.  
  9. //Here I want to make an array of a, b and c,
  10. //then use it in for loop with the ints and floats.
  11.  
  12. }`
  13.  
  14. struct T {
  15. A obj1;
  16. B obj2;
  17. C obj3;
  18. };
  19.  
  20. #include <iostream>
  21.  
  22. struct Person
  23. {
  24. std::string name;
  25. int age;
  26. std::string job;
  27. };
  28.  
  29. int main()
  30. {
  31. Person people[10];
  32.  
  33. //I am a normal one.
  34. for(int i=0; i<10; ++i)
  35. {
  36. people[i].name = "usar";
  37. people[i].age = i;
  38. people[i].job = "Astronaut";
  39. }
  40.  
  41. //foreach loop
  42. for(Person p: people)
  43. {
  44. std::cout << "Name: "<< p.name << "n";
  45. std::cout << "Age: "<< p.age << "n";
  46. std::cout << "Job: "<< p.job << "n";
  47. }
  48.  
  49. return 0;
  50. }
  51.  
  52. struct Car
  53. {
  54. int engine;
  55. string brandName;
  56. };
  57.  
  58. Car list[2]={{3000, "BMW"},{2200, "Mercedes-Benz"}};
  59.  
  60. Car list[2];
  61.  
  62. struct Base
  63. {
  64.  
  65. virtual ~Base(){}
  66.  
  67. virtual int GetInt()
  68. {
  69. throw "Not implemented";
  70. return 0;
  71. }
  72. virtual float GetFloat()
  73. {
  74. throw "Not implemented";
  75. return 0.0f;
  76. };
  77. };
  78.  
  79. struct A : public Base
  80. {
  81. int a;
  82. virtual int GetInt()
  83. {
  84. return a;
  85. }
  86. };
  87.  
  88. struct B : public Base
  89. {
  90. int b;
  91. virtual int GetInt()
  92. {
  93. return b;
  94. }
  95. };
  96.  
  97. struct C : public Base
  98. {
  99. float c;
  100. virtual float GetFloat()
  101. {
  102. return c;
  103. }
  104. };
  105.  
  106. int main()
  107. {
  108. A a; B b; C c;
  109.  
  110. Base* array[ 3 ] = { &a, &b, &c };
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement