overloaded functions in multiple inheritance.

Discussion in 'C++' started by DX, Jun 11, 2004.

  1. DX

    DX Guest

    in MSVC7 the following seems to work:

    class A { public: virtual void func1(void); };
    class B { public: virtual void func2(void); };

    class AB : public A, public B
    {
    virtual void A::func1(void) {return 0;};
    virtual void B::func1(void) {return 1;};
    }

    This is great, except my two versions of func1 are actually huge, and
    I'd like to put them into two separate files. In order to do this,
    I'm doing something like:

    class AB : public A, public B
    {
    virtual void A::func1(void);
    virtual void B::func1(void);
    }

    void AB::A::func1(void)
    { return 0; };

    void AB::A::func1(void)
    { return 1; };

    However, when I do this, I get a compiler error:
    error C2509: 'func1': member function not declared in 'AB'

    Anyone have any clue what I'm doing wrong? Syntax error somewhere?
     
    DX, Jun 11, 2004
    #1
    1. Advertising

  2. "DX" <> wrote...
    > in MSVC7 the following seems to work:
    >
    > class A { public: virtual void func1(void); };
    > class B { public: virtual void func2(void); };


    Did you actually mean

    class B { public: virtual void func1(void); };

    ???

    >
    > class AB : public A, public B
    > {
    > virtual void A::func1(void) {return 0;};
    > virtual void B::func1(void) {return 1;};
    > }


    Really? I just checked with 7.1, and as expected, the code is full
    of errors.

    >
    > This is great,


    No, it isn't. Your code is not C++, how can it be "great"?

    > [..]
    > Anyone have any clue what I'm doing wrong? Syntax error somewhere?


    Plenty. What are you trying to do?

    V
     
    Victor Bazarov, Jun 11, 2004
    #2
    1. Advertising

  3. DX

    DaKoadMunky Guest

    You didn't state what it is you are trying to do but I am going to employ my
    psychic powers and suggest that you take a look at this link...

    http://www.gotw.ca/gotw/039.htm
     
    DaKoadMunky, Jun 11, 2004
    #3
  4. DX

    DX Guest

    I was basically trying to have class AB implement two versions of
    func1, one for each base class.

    I thought this was not possible in C++. I was quite confused because
    someone else passed me the original code. Anyways, I found my
    solution here:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/deriv_14.asp

    That was exactly what I was trying to do.
    My guess is it's specific to MSVC, using the "interface" keyword.
     
    DX, Jun 11, 2004
    #4
    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. DX
    Replies:
    0
    Views:
    359
  2. Joe P
    Replies:
    1
    Views:
    302
    Pete Becker
    Jun 21, 2005
  3. Replies:
    8
    Views:
    367
  4. jrraines

    overloaded name + inheritance

    jrraines, Mar 20, 2010, in forum: C++
    Replies:
    1
    Views:
    454
    Michael Tsang
    Mar 22, 2010
  5. John Wickerbee

    Inheritance of overloaded ++ operator issue

    John Wickerbee, Oct 2, 2011, in forum: C Programming
    Replies:
    0
    Views:
    425
    John Wickerbee
    Oct 2, 2011
Loading...

Share This Page