Sponsored Content
Top Forums Programming Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem Post 302816047 by royalibrahim on Monday 3rd of June 2013 08:12:41 AM
Old 06-03-2013
Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem

Hi,

In multi-level inheritance:

Code:
class A { 
public:
   void fun() { cout << "A" << endl; }
};

class B : public A {
public:
   void fun() { cout << "A" << endl; }
};

class C : public B { };

int main() {
    C c;
    c.fun();  // Ans: A
}

In multiple inheritance:

Code:
class A {
public:
   void fun() { cout << "A" << endl; }
};

class B {
public:
   void fun() { cout << "B" << endl; }
};

class C : public A, public B { /* public: using B::fun; */ };

int main() {
    C c;
    c.fun(); // Error: request for member function is ambiguous // use:  c.A::fun();
}

I would like to know, why there is no ambiguous problem in the multi-level inheritance code (1st code) which is compiling and giving output perfectly when both the base classes are having the same function signature. Where as it is giving error in the multiple inheritance code (2nd code).
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl - variable inheritance

Hey Everyone, Does anyone know how - or if it's even possible - for a child perl script to inherit the variables of a parent perl script? In a shell script, you would use "export" for example. I am running Perl 5.8. Basically, let's say "perl1.pl" calls "perl2.pl" and I want "perl2.pl" to... (2 Replies)
Discussion started by: gsatch
2 Replies

2. Shell Programming and Scripting

Makefile: Parent - Child Inheritance and export

Hi, I have a number of Makefiles, including a couple of files that I include in Makefiles, a few scripts that are executed through Makefiles, and I have problems with environment variables that are not inherited to the scripts properly. Simplified scenario: rootdir/Makefile: all: ... (1 Reply)
Discussion started by: Shompis
1 Replies

3. AIX

WLM inheritance

Is none of you using WLM? A search gives no matches.... Anyway, I have set up a class with inheritance = yes. In the rules characteristics I have chosen a shell script as an application. This script is caught by the class, but not the child processes, which have the PID of the script as the... (6 Replies)
Discussion started by: firefox111
6 Replies

4. Programming

C++ Inheritance problem??????

Hi friends, I hope u people are ok and doing fine. I have this small problem with the derived class. I have created te base class and there is a small problem with the definition of the derived class which the compiler is pointing out, could you please help me. Here is my code #ifndef... (2 Replies)
Discussion started by: gabam
2 Replies

5. Shell Programming and Scripting

Inheritance in Perl

package Inventory_item; sub new { my($class) = shift; bless { "PART_NUM" => undef, "QTY_ON_HAND" => undef }, $class; } package main; $item = Inventory_item->new(); Can any one please help me in brief explaining the line... (5 Replies)
Discussion started by: parthmittal2007
5 Replies

6. Programming

Inheritance

whats the use of inheriting with access specifier as private..? Please specify the answer with a simple example... Regards -- Madhu (5 Replies)
Discussion started by: MadhuM
5 Replies

7. Red Hat

Ulimit Inheritance

Hi , If i start mysqld or httpd as root user which inturn starts them as "mysql" or "apache" user, will the ulimit of "root" user or ulimit of "mysql/apache" user be set for the mysql/apache processes. My understanding is that the ulimit of the user who initiates the process(root in this... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

8. Programming

Size of derived class, in case of multiple inheritance

Why, here the size of class 'Derived' is 8 ? class Base1 { public: virtual void f() { } }; class Base2 { public: virtual void f() { } }; class Derived : public Base1, Base2 { public: virtual void f() { } }; (1 Reply)
Discussion started by: techmonk
1 Replies

9. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./oop.py", line 20, in <module> y = DerivedClass("Manu") File "./oop.py", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies
CAIROPSSURFACE(3)							 1							 CAIROPSSURFACE(3)

The CairoPsSurface class

INTRODUCTION
CLASS SYNOPSIS
CairoPsSurface CairoPsSurfaceextends CairoSurface Methods o public CairoPsSurface::__construct (string $file, float $width, float $height) o public void CairoPsSurface::dscBeginPageSetup (void ) o public void CairoPsSurface::dscBeginSetup (void ) o public void CairoPsSurface::dscComment (string $comment) o public bool CairoPsSurface::getEps (void ) o publicstatic array CairoPsSurface::getLevels (void ) o publicstatic string CairoPsSurface::levelToString (int $level) o public void CairoPsSurface::restrictToLevel (string $level) o public void CairoPsSurface::setEps (string $level) o public void CairoPsSurface::setSize (string $width, string $height) Inherited methods o public CairoSurface::__construct (void ) o public void CairoSurface::copyPage (void ) o public void CairoSurface::createSimilar (CairoSurface $other, int $content, string $width, string $height) o public void CairoSurface::finish (void ) o public void CairoSurface::flush (void ) o public int CairoSurface::getContent (void ) o public array CairoSurface::getDeviceOffset (void ) o public void CairoSurface::getFontOptions (void ) o public int CairoSurface::getType (void ) o public void CairoSurface::markDirty (void ) o public void CairoSurface::markDirtyRectangle (string $x, string $y, string $width, string $height) o public void CairoSurface::setDeviceOffset (string $x, string $y) o public void CairoSurface::setFallbackResolution (string $x, string $y) o public void CairoSurface::showPage (void ) o public int CairoSurface::status (void ) o public void CairoSurface::writeToPng (string $file) PHP Documentation Group CAIROPSSURFACE(3)
All times are GMT -4. The time now is 03:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy