[ create a new paste ] login | about

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

C++, pasted on May 6:
    #include <iostream>

    using namespace std;

    // file 1

    class a
    {
    	public:
    		virtual void m() { }
    		virtual ~a() { }
    };

    // file 2

    class b : public a
    {
    	int x;
    	
    	public:
    		void m() { cout << "b!\n"; }
    };
    
    // file 3

    class c : public a
    {
    	a *s;
    	
    	public:
    		// PROBLEMATIC SECTION
    		c() { s = new b[10]; } // s = new b;
    		void m() { for(int i = 0; i < 10; i++) s[i].m(); } // s->m();
    		~c() { delete[] s; } // delete s;
    		// END PROBLEMATIC SECTION
    };

    // file 4

    int main(void)
    {
    	c o;
    	
    	o.m();
    	
    	return 0;
    }


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: