Hi, Even if your Base doesn't have any data members but needs to do something when it is instantiated (like notify some third party about it), you still need to have a constructor.
If, by some chance, your Base class doesn't need to do anything when it is instantiated as part of some other object (of a derived class), then the default (compiler-provided) constructor would undoubtedly be sufficient. I got the above lines from the following posting: http://bytes.com/forum/thread139508.html -nag. On Tue, Oct 7, 2008 at 12:18 AM, Gopi Krishna Komanduri < [EMAIL PROTECTED]> wrote: > Hi Folks, > I have one basic query on constructors and abstract classes.. > > My query is : > why do we require constructor in abstract classes? One reason could be > if we have any member variables in abstract classes , to initialize them we > can use.. but when that constructor is called , that means an object for > that class is created . which implies an object for abstract class is > created which according to theroy is error as abstract classes are non > instantiable. > Please pull me out from this confusion.. > Code exm: > > // Constructor$AbsCls.cpp : Defines the entry point for the console > application. > // > #include "stdafx.h" > #include<stdio.h> > #include<iostream> > using namespace std; > class abscls > { > public: > int x; > abscls() > { > x = 30; > cout<<"I m in constructor "<<endl; > } > virtual void show()=0; > }; > class absclsder:public abscls > { > public: > int y; > absclsder() > { > cout<<"I m in abstract class der cls"<<endl; > } > void show() > { > cout<<"I m in show of der"<<endl; > } > }; > int _tmain(int argc, _TCHAR* argv[]) > { > class absclsder obj; > return 0; > } > > > Thx, > --Gopi > > Add more friends to your messenger and enjoy! Go to > http://messenger.yahoo.com/invite/ > > [Non-text portions of this message have been removed] > > > -- Cheers, -nag. [Non-text portions of this message have been removed]
