public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15797] New: static_casts of objects on stack only point to copy of object
@ 2004-06-03 18:10 loeffel77 at yahoo dot com
2004-06-03 18:30 ` [Bug c++/15797] " bangerth at dealii dot org
0 siblings, 1 reply; 2+ messages in thread
From: loeffel77 at yahoo dot com @ 2004-06-03 18:10 UTC (permalink / raw)
To: gcc-bugs
#include <iostream>
using namespace std;
class base
{
public:
int val1;
base():val1(10)
{cout << "Where: "<< this << endl;}
};
class child: public base
{ public:
int val2;
child():val2(20)
{cout << "Where: "<< this << endl;}
};
int main(void)
{
child myclass;
cout << "Where child: " << &myclass << endl;
cout << "Where static_cast< base> " << &(static_cast<base> (myclass)) << endl;
cout << "=================="<< endl;
cout << "Changing val1 to 11" << endl;
static_cast<base>(myclass).val1=11; // This should change
myclass.val1;
cout << "val1 in child: " << myclass.val1 << endl; // But does not work
cout << "val1 in base: " << static_cast<base>(myclass).val1 << endl;
return 0;
}
--
Summary: static_casts of objects on stack only point to copy of
object
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: loeffel77 at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15797
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/15797] static_casts of objects on stack only point to copy of object
2004-06-03 18:10 [Bug c++/15797] New: static_casts of objects on stack only point to copy of object loeffel77 at yahoo dot com
@ 2004-06-03 18:30 ` bangerth at dealii dot org
0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2004-06-03 18:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-06-03 18:30 -------
You need to cast to a reference to the base class instead.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15797
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-06-03 18:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-03 18:10 [Bug c++/15797] New: static_casts of objects on stack only point to copy of object loeffel77 at yahoo dot com
2004-06-03 18:30 ` [Bug c++/15797] " bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).