From: "Moore, Mathew L" <MooreML@BATTELLE.ORG>
To: "'gcc-help@gcc.gnu.org'" <gcc-help@gcc.gnu.org>
Subject: g++ 3.2 and dynamic_cast for private base
Date: Tue, 17 Sep 2002 13:16:00 -0000 [thread overview]
Message-ID: <2F05A390F72A0A409390E016D23E45E8042DBD64@ns-bco-mse4.im.battelle.org> (raw)
I recently downloaded and installed gcc 3.2, and now I find that I cannot
use the dynamic_cast operator for casting `this' to a private base class
type. I know this latest release conforms more to the ISO standard, but I
can't find anything in the standard that forbids this operation.
I would appreciate if someone could tell me where I went awry!
Thanks in advance for your help.
--Matt
The following code gives me the errors:
test.cpp: In member function `int C::methodC() const':
test.cpp:28: `A' is an inaccessible base of `C'
test.cpp:29: `A' is an inaccessible base of `C'
(lines are marked by comments in the code).
Built with `g++ --ansi -Wall '
====================
#include <iostream>
class A
{
public:
int methodA() const {
return 1;
}
};
class B : public A
{
public:
int methodB() const {
const A& a = dynamic_cast<const A&>(*this);
return a.methodA() + 1;
}
};
class C : private B
{
public:
int methodC() const {
// This works:
const A& implicit_cast = *this;
// But the next two source lines generate "inaccessable base"
// errors.
const A* pa = dynamic_cast<const A*>(this);
const A& a = dynamic_cast<const A&>(*this);
return implicit_cast.methodA() + 2;
}
};
int
main(int argc, char** argv)
{
C c;
std::cout << "result = " << c.methodC();
return 0;
}
reply other threads:[~2002-09-17 20:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=2F05A390F72A0A409390E016D23E45E8042DBD64@ns-bco-mse4.im.battelle.org \
--to=mooreml@battelle.org \
--cc=gcc-help@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).