Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10470

virtual function and segmentation fault

From asit <lipun4u@gmail.com>
Newsgroups comp.lang.c++
Subject virtual function and segmentation fault
Date 2011-09-25 07:58 -0700
Organization http://groups.google.com
Message-ID <15048105.1151.1316962687519.JavaMail.geo-discussion-forums@prng5> (permalink)

Show all headers | View raw


Look at the following code snippet..


#include <iostream>

using namespace std;

class ex
{
        int i;
public:
        ex(int ii=0):i(ii) {}

        ~ex() { cout<<"dest"<<endl; }

        virtual void show()
        {
                cout<<"show fun called"<<endl;
        }

};

int main()
{
        ex *ob = NULL;
        ob->show();
        return 0;
}


The output here is segmentation fault. 

If I make show non-virtual, there is no segmentation fault.

Can somebody explain me the reason ??

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

virtual function and segmentation fault asit <lipun4u@gmail.com> - 2011-09-25 07:58 -0700
  Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 16:30 +0100
    Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 18:32 +0100
      Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 18:50 +0100
        Re: virtual function and segmentation fault Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 13:08 -0500
          Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 19:16 +0100
            Re: virtual function and segmentation fault Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 14:15 -0500
              Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 20:28 +0100
  Re: virtual function and segmentation fault asit <lipun4u@gmail.com> - 2011-09-25 08:43 -0700
    Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 16:51 +0100
  Re: virtual function and segmentation fault Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 12:45 -0500
  Re: virtual function and segmentation fault Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-25 13:53 -0400
    Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 19:04 +0100
      Re: virtual function and segmentation fault Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 13:18 -0500
        Re: virtual function and segmentation fault Leigh Johnston <leigh@i42.co.uk> - 2011-09-25 19:22 +0100
          Re: virtual function and segmentation fault Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 14:51 -0500
      Re: virtual function and segmentation fault Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-25 15:12 -0400
      Re: virtual function and segmentation fault Miles Bader <miles@gnu.org> - 2011-09-26 08:49 +0900

csiph-web