From: "bowman" Newsgroups: comp.os.msdos.djgpp References: <7fr7hv$ouc$1 AT nntp1 DOT atl DOT mindspring DOT net> Subject: Re: Pointer dec call the constructor? Lines: 47 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Message-ID: Date: Fri, 23 Apr 1999 20:48:37 -0600 NNTP-Posting-Host: 208.26.212.65 X-Trace: newsfeed.slurp.net 924922158 208.26.212.65 (Fri, 23 Apr 1999 21:49:18 CDT) NNTP-Posting-Date: Fri, 23 Apr 1999 21:49:18 CDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Lark wrote in message news:7fr7hv$ouc$1 AT nntp1 DOT atl DOT mindspring DOT net... > Does a pointer declaration call the constructor of the type of object it > points to? For example: you were almost there. Why not compile it and find out? -------------------- experiment.cpp ----------------------- #include using namespace std; class A { public: A(){x=5; cout << "constructing A" << endl;} int x; }; class B:public A { public: B(){y=7; cout << "constructing B" << endl;} int y; }; int main() { cout << "in main" << endl; A * ob; cout << "creating a new B" << endl; ob = new B(); cout << "leaving main" << endl; return 0; }