| www.delorie.com/archives/browse.cgi | search |
| From: | "bowman" <bowman AT montana DOT com> |
| 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: | <OiaU2.502$8j6.1321@newsfeed.slurp.net> |
| 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 <rlark at mbhs dot edu> 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 <iostream>
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;
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |