public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "loeffel77 at yahoo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/15797] New: static_casts of objects on stack only point to copy of object
Date: Thu, 03 Jun 2004 18:10:00 -0000	[thread overview]
Message-ID: <20040603181038.15797.loeffel77@yahoo.com> (raw)

#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


             reply	other threads:[~2004-06-03 18:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-03 18:10 loeffel77 at yahoo dot com [this message]
2004-06-03 18:30 ` [Bug c++/15797] " bangerth at dealii dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040603181038.15797.loeffel77@yahoo.com \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).