[ create a new paste ] login | about

Link: http://codepad.org/xKlRKGGk    [ raw code | output | fork ]

GiM - C++, pasted on Apr 24:
#include <iostream>                                                                                     
#include <vector>                                                                                       
                                                                                                        
class A {                                                                                               
    public:                                                                                             
        int a, b, c;                                                                                    
        A() { a=1; b=2; c=3;                                                                            
            std::cout << "constr" <<  a << ":" << b << ":" << c  << std::endl;                          
        }                                                                                               
        void pokaz() { std::cout << "blurp" <<  a << ":" << b << ":" << c  << std::endl; }              
};                                                                                                      
                                                                                                        
class B : public A {                                                                                    
    int x,y,z,u,v;                                                                                      
    public:                                                                                             
    B()                                                                                                 
    {                                                                                                   
        std::cout << " w konstr B: " << this << " ] " << std::endl;                                     
    }                                                                                                   
    int bing(int x) { return (x+2); }                                                                   
};                                                                                                      
                                                                                                        
typedef std::vector<A*> Weka;                                                                           
                                                                                                        
int main()                                                                                              
{                                                                                                       
    Weka wek;                                                                                           
    Weka::iterator wek_i;                                                                               
    A *tempA;                                                                                           
    B *tempB;                                                                                           
                                                                                                        
    wek.push_back(new B);                                                                               
    wek.push_back(new B);                                                                               
    wek.push_back(new B);                                                                               
    wek.push_back(new B);                                                                               
                                                                                                        
    int x=0;                                                                                            
    for (wek_i = wek.begin(); wek_i != wek.end(); wek_i++, x++)                                         
    {                                                                                                   
        tempA = *wek_i;                                                                                 
        tempA->a = 6 +x;                                                                                
        tempA->pokaz();                                                                                 
    }                                                                                                   
                                                                                                        
    for (wek_i = wek.begin(); wek_i != wek.end(); wek_i++, x++)                                         
    {                                                                                                   
        tempB = static_cast<B*>(*wek_i);                                                                
        tempB->b = 10+x;                                                                                
        tempB->pokaz();                                                                                 
        tempB->bing(2);                                                                                 
    }                                                                                                   
                                                                                                        
                                                                                                        
    return 0;                                                                                           
}                                                                                                       
                                                                                                        


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
constr1:2:3
 w konstr B: 0x8056438 ] 
constr1:2:3
 w konstr B: 0x80565a8 ] 
constr1:2:3
 w konstr B: 0x8056610 ] 
constr1:2:3
 w konstr B: 0x8056650 ] 
blurp6:2:3
blurp7:2:3
blurp8:2:3
blurp9:2:3
blurp6:14:3
blurp7:15:3
blurp8:16:3
blurp9:17:3


Create a new paste based on this one


Comments: