Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C++] Inheritance Diamond Problem
#1
I will just leave it here...

    C++-Code:
#include <iostream>
 
using namespace std;
 
class Root
{
    public: virtual int foo()
    {
        return 0;
    }
};
class Mid1 : Root
{
    public: int foo()
    {
        return 1;
    }
};
class Mid2 : Root
{
    public: int foo()
    {
        return 2;
    }
};
class Top : Mid1, Mid2 //changing order changes output
{
 
};
 
void bar(void* ptr)
{
    Root* root = (Root*)ptr;
    cout << root->foo();
}
 
int main()
{
    Top* t = new Top();
    bar(t);
 
    return 0;
}
Ultimately, my constant dissatisfaction with the way things are becomes the driving force behind everything I do.
[Image: sigline.png]
LF2 IDE - Advanced visual data changer featuring instant data loader
LF2 Sprite Sheet Generator - Template based sprite sheet generator based on Gad's method
[Image: sigline.png]
There is no perfect language, but C++ is the worst.
Reply
Thanks given by:


Messages In This Thread
[C++] Inheritance Diamond Problem - by NightmareX1337 - 01-06-2016, 07:59 PM
RE: [C++] Inheritance Diamond Problem - by A-Man - 01-06-2016, 09:10 PM



Users browsing this thread: 1 Guest(s)