home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!news.mentorg.com!sdl!adk
- From: adk@Warren.MENTORG.COM (Ajay Kamdar)
- Subject: Re: copy ctor and inheritance
- Message-ID: <1992Sep4.143644.5075@Warren.MENTORG.COM>
- Organization: Mentor Graphics Corp. - IC Group
- References: <6143@taurus.cs.nps.navy.mil>
- Date: Fri, 4 Sep 1992 14:36:44 GMT
- Lines: 27
-
- In article <6143@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
- >
- > How do I get the copy constructor of a base class to get invoked
- > when I use a copy constructor for a base class ?
- >
- > In the following example I get the behaviour I want (AT&T 2.1)
- > if I leave it up to the compiler to create the copy constructor for B,
- > but if I write my own, the copy constructor for the base class A never
- > gets invoked. (It does not matter whether or not I define the copy constructor
- > for the base class, A).
-
- >
- > // If the constructor below is commented out, A::val is copied
- > // B(const B& b) { vv = b.vv; cout << "B(&B) invoked\n"; }
-
- B's copy constructor should be written as:
-
- B(const B& b) : A(b) { vv = b.vv; cout << "B(&B) invoked\n"; }
-
-
- - Ajay
-
- --
- I speak for none but myself.
-
- Ajay Kamdar Email : ajay_kamdar@mentorg.com
- Mentor Graphics, IC Group (Warren, NJ) Phone : (908) 580-0102
-