Topic: multiple inheritance ambiguity question
Author: "PuzzledwithC++" <yogpjosh@gmail.com>
Date: Thu, 1 Oct 2009 11:12:59 CST Raw View
HI,
consider the code below
class base
{
public:
void display()
{ }
};
class der1:public base
{
};
class der2:public base
{
};
class client :public der1,public der2
{
public:
void test()
{
//display();//ambigous call.Compilation error.
base::display();//no compilation error.
}
};
void main()
{
client cl;
cl.test();
}
So calling display() inside client::test() will give a valid
compilation error.
But when I call base::display(),the program runs fine.
My confusion is when I call base::display(),which base is being
recognized here?.Is it a base part from der1 or der2.?
I believe the call base::display() gets modified like
static_cast<der1*>(this)->base::display().
Thanks and regards,
Yogesh
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Leigh Johnston" <leigh@i42.co.uk>
Date: Thu, 1 Oct 2009 18:24:19 CST Raw View
Are you using VC++? Your code fails to compile on comeau and g++.
/Leigh
"PuzzledwithC++" <yogpjosh@gmail.com> wrote in message
news:cf24bc37-d2b2-430e-9852-ab9f1bdaf5ee@v15g2000prn.googlegroups.com...
> HI,
>
> consider the code below
>
> class base
> {
> public:
> void display()
> { }
> };
> class der1:public base
> {
> };
> class der2:public base
> {
> };
>
> class client :public der1,public der2
> {
> public:
> void test()
> {
> //display();//ambigous call.Compilation error.
> base::display();//no compilation error.
> }
> };
> void main()
> {
> client cl;
> cl.test();
>
> }
>
> So calling display() inside client::test() will give a valid
> compilation error.
> But when I call base::display(),the program runs fine.
> My confusion is when I call base::display(),which base is being
> recognized here?.Is it a base part from der1 or der2.?
> I believe the call base::display() gets modified like
> static_cast<der1*>(this)->base::display().
>
>
> Thanks and regards,
> Yogesh
>
> --
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
>
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "David Sachs" <sachs1926@comcast.net>
Date: Fri, 2 Oct 2009 15:21:52 CST Raw View
Sounds like a compiler bug. You should report this to the vendor of the
compiler you are using.
"PuzzledwithC++" <yogpjosh@gmail.com> wrote in message
news:cf24bc37-d2b2-430e-9852-ab9f1bdaf5ee@v15g2000prn.googlegroups.com...
> HI,
>
> consider the code below
>
> class base
> {
> public:
> void display()
> { }
> };
> class der1:public base
> {
> };
> class der2:public base
> {
> };
>
> class client :public der1,public der2
> {
> public:
> void test()
> {
> //display();//ambigous call.Compilation error.
> base::display();//no compilation error.
> }
> };
> void main()
> {
> client cl;
> cl.test();
>
> }
>
> So calling display() inside client::test() will give a valid
> compilation error.
> But when I call base::display(),the program runs fine.
> My confusion is when I call base::display(),which base is being
> recognized here?.Is it a base part from der1 or der2.?
> I believe the call base::display() gets modified like
> static_cast<der1*>(this)->base::display().
>
>
> Thanks and regards,
> Yogesh
>
> --
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
>
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Paul Bibbings <paul_bibbings@googlemail.com>
Date: Fri, 2 Oct 2009 15:22:37 CST Raw View
On 01/10/2009 18:12, PuzzledwithC++ wrote:
> HI,
>
> consider the code below
>
> class base
> {
> public:
> void display()
> { }
> };
> class der1:public base
> {
> };
> class der2:public base
> {
> };
>
> class client :public der1,public der2
> {
> public:
> void test()
> {
> //display();//ambigous call.Compilation error.
> base::display();//no compilation error.
> }
> };
> void main()
> {
> client cl;
> cl.test();
>
> }
I can get this to compile with VC++ 2008, but it really shouldn't succeed.
Without virtual inheritance of both der1 and der2 from base, both calls in
client::test() should be equally ambiguous.
gcc 4.4.1 will complain on both calls, and correctly so, just as it complains at
having main return void.
Regards
Paul Bibbings
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]