Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct A { int a; };
- struct B { int b; };
- struct C { float c; };
- int main()
- {
- A a; B b; C c;
- //Here I want to make an array of a, b and c,
- //then use it in for loop with the ints and floats.
- }`
- struct T {
- A obj1;
- B obj2;
- C obj3;
- };
- #include <iostream>
- struct Person
- {
- std::string name;
- int age;
- std::string job;
- };
- int main()
- {
- Person people[10];
- //I am a normal one.
- for(int i=0; i<10; ++i)
- {
- people[i].name = "usar";
- people[i].age = i;
- people[i].job = "Astronaut";
- }
- //foreach loop
- for(Person p: people)
- {
- std::cout << "Name: "<< p.name << "n";
- std::cout << "Age: "<< p.age << "n";
- std::cout << "Job: "<< p.job << "n";
- }
- return 0;
- }
- struct Car
- {
- int engine;
- string brandName;
- };
- Car list[2]={{3000, "BMW"},{2200, "Mercedes-Benz"}};
- Car list[2];
- struct Base
- {
- virtual ~Base(){}
- virtual int GetInt()
- {
- throw "Not implemented";
- return 0;
- }
- virtual float GetFloat()
- {
- throw "Not implemented";
- return 0.0f;
- };
- };
- struct A : public Base
- {
- int a;
- virtual int GetInt()
- {
- return a;
- }
- };
- struct B : public Base
- {
- int b;
- virtual int GetInt()
- {
- return b;
- }
- };
- struct C : public Base
- {
- float c;
- virtual float GetFloat()
- {
- return c;
- }
- };
- int main()
- {
- A a; B b; C c;
- Base* array[ 3 ] = { &a, &b, &c };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement