Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Base {
- int av;
- virtual bool is (int value) const
- {
- return av == value;
- }
- virtual void print() const
- {
- cout << av << endl;
- }
- };
- struct A : public Base {
- int bv;
- virtual bool is (int value) const
- {
- return bv == value;
- }
- virtual void print () const
- {
- cout << bv << endl;
- }
- };
- struct database {
- vector <Base*> basev;
- Base NBase;
- database () { NBase.av = 0; }
- Base* findb (int value) {
- for (int i = 0; i < basev.size (); ++i) {
- if(basev[i]->is (value));
- return basev[i];
- }
- return &NBase;
- }
- } db;
- int main( ) {
- Base der;
- der.av = 5;
- db.basev.push_back (&der);
- Base* found = db.findb (5);
- found->print ();
- }
Advertisement
Add Comment
Please, Sign In to add comment