disambiguate static multiply inherited class functions

Discussion in 'C++' started by wes, Mar 1, 2007.

  1. wes

    wes Guest

    Hi,
    Is there anyway to disambiguate multiply inherited static class
    functions?

    template<T>
    class A
    {
    static doit() {}
    }

    class B : public A<B>
    {

    }

    class C : public A<C>, public B
    {

    }

    C::doit() <----error ambiguous!

    any way to specify which C::doit() function gets called?
    wes, Mar 1, 2007
    #1
    1. Advertising

  2. wes

    Piyo Guest

    wes wrote:

    >
    > any way to specify which C::doit() function gets called?
    >


    I first tried virtual inheritance but I forgot that
    class A<B> and class A<C> are still distinct classes and
    thus does not help. The only way to disambiguate then is
    to fully qualify what you want to call. See how in main,
    I can call them directly without ambiguity.

    HTH

    -------------------------------------
    template<typename T>
    class A
    {
    public:
    static T doit() { return T(); }
    };

    class B : public A<B>
    {
    public:
    };

    class C : public A<C>, public B
    {
    public:
    };

    int
    main()
    {
    A<C>::doit();
    B::doit();
    //C::doit();
    }
    Piyo, Mar 2, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashok
    Replies:
    14
    Views:
    727
    Marcelo Pinto
    Nov 10, 2004
  2. puzzlecracker
    Replies:
    1
    Views:
    276
    Shezan Baig
    Feb 26, 2005
  3. Rajorshi
    Replies:
    1
    Views:
    3,165
    Duncan Booth
    May 20, 2004
  4. Janaka Perera
    Replies:
    12
    Views:
    490
    Janaka Perera
    May 30, 2007
  5. 7stud --
    Replies:
    11
    Views:
    396
    7stud --
    Nov 9, 2007
Loading...

Share This Page