Advertisement
Carcigenicate

Simple Example

Jan 21st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Base {
  7.     int av;
  8. };
  9.  
  10. struct A : public Base {
  11.     int bv;
  12. };
  13.  
  14. struct database {
  15.     vector <Base> basev;
  16.     Base NBase;
  17.    
  18.     database () { NBase.av = 0; }
  19.    
  20.     Base& findb (int value) {
  21.         for (int i = 0; i < basev.size (); ++i) {
  22.             if (basev [i].av == value) return basev [i];
  23.         }
  24.         return NBase;
  25.     }
  26.    
  27. } db;
  28.    
  29.  
  30. int main( ) {
  31.    
  32.     Base der;
  33.     der.av = 5;
  34.     db.basev.push_back (der);
  35.    
  36.     Base found = db.findb (5);
  37.    
  38.     cout << found.av << endl;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement