public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amit_choudhary at mindtree dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/19665] New: Can access private member function if it is virtual Date: Fri, 28 Jan 2005 09:20:00 -0000 [thread overview] Message-ID: <20050128092049.19665.amit_choudhary@mindtree.com> (raw) I was doing some experiments and I discovered that I can access a private member function if I make it virtual and do few other tricks. The code is below. The "Base class called" is printed. So, basically when someone wants to access a virtual function (by explicit type casting), there is no check whether that virtual function is private or not. But if I try to call it directly, it checks that it is a private member function. May be g++ compiler needs to be modified. #include<iostream> using namespace std; class A { private: virtual void abc() { cout << "Base Class called\n"; } }; class B : public A { public: void abc() { cout << "Derived Class called\n"; } }; int main() { A a; B *b = static_cast<B *>(&a); b->abc(); } [amit]$ g++ c++-bug.cpp c++-bug.cpp:6: warning: all member functions in class `A' are private [amit]$ ./a.out Base Class called [amit]$ -- Summary: Can access private member function if it is virtual Product: gcc Version: 3.3.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: amit_choudhary at mindtree dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: g++ c++-bug.cpp c++-bug.cpp:6: warning: all member functions in GCC host triplet: gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) GCC target triplet: Configured with: ../configure --prefix=/usr -- mandir=/usr/share/ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19665
next reply other threads:[~2005-01-28 9:20 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-01-28 9:20 amit_choudhary at mindtree dot com [this message] 2005-01-28 9:29 ` [Bug c++/19665] " amit_choudhary at mindtree dot com 2005-01-28 9:42 ` falk at debian 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=20050128092049.19665.amit_choudhary@mindtree.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: linkBe 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).