Path: utzoo!attcan!uunet!decwrl!wuarchive!psuvax1!psuvm!cunyvm!ndsuvm1!mtus5!eacons From: EACONS@MTUS5.BITNET (Ernie Anderson) Newsgroups: comp.lang.c++ Subject: Whats wrong with this picture (or am I slow?) Message-ID: <90281.014850EACONS@MTUS5.BITNET> Date: 8 Oct 90 06:48:50 GMT Organization: Computing Technology Services, Michigan Technological Univ. Lines: 30 Hello all... I'm trying to pound the fundamentals of C++ through my thick skull, and I've run into a stumper. In "Programming in C++" by Dewhurst and Stark in chapter 3 where they introduce their brain-dead example string class, I have a question. The code in question is #include #include class String { char *str; public: String() {str = new char[1]; *str = 0; } String(char *); void print() {printf(" %s", str); } ... }; Then later they do something like: String a; ... a = String (buffer); Now when a was declared, a single character of storage was allocated, right? and when buffer was converted to a String and assigned to a, the value of str in that temporary instance for buffer was copied to a's str, right? So isn't the byte of storage allocated by declaring a lost? Please either confirm this, or tell me where I'm going wrong... Ernest J. Anderson eacons@mtus5.cts.mtu.edu, eacons@mtus5.bitnet, ejanders@symmetry.cs.mtu.edu