From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9233 invoked by alias); 29 Jan 2002 00:38:35 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 9209 invoked by uid 61); 29 Jan 2002 00:38:34 -0000 Date: Mon, 28 Jan 2002 16:38:00 -0000 Message-ID: <20020129003834.9208.qmail@sources.redhat.com> To: bridean@ameritech.net, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org From: rodrigc@gcc.gnu.org Reply-To: rodrigc@gcc.gnu.org, bridean@ameritech.net, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org X-Mailer: gnatsweb 2.9.3 Subject: Re: c++/5517: Internal variables in classes not stored correctly X-SW-Source: 2002-01/txt/msg01000.txt.bz2 List-Id: Synopsis: Internal variables in classes not stored correctly State-Changed-From-To: open->closed State-Changed-By: rodrigc State-Changed-When: Mon Jan 28 16:38:33 2002 State-Changed-Why: This is not a bug in the compiler, but a bug in your program. Look at your mult() function: Polynomial Polynomial::mult(double num) { printf("Current polynomial is: "); this->print(); Polynomial ans(degree); printf("Current polynomial is: "); this->print(); int i; for (i=degree; i>=0; i--) { ans.coeff[i] = num * coeff[i]; printf("coeff[i] is: %0.12lf\n", coeff[i]); } return ans; } Your are creating a Polynomial on the stack and then returning it. But when the scope of the mult() function ends, the destructor will be called on ans! If you gave your class a Polynomial a copy constructor, and did something like: return Polynomial(ans); you would be OK. This is not a gcc bug. Refer to a good C++ book, or ask questions on the comp.lang.c++.moderated newsgroup. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5517