Why compilation error here?

Discussion in 'C++' started by Goran, Sep 12, 2006.

  1. Goran

    Goran Guest

    Hi all!

    Example here doesn't compile in both VC++ and gcc. It's like Get(int&)
    somehow hides Get() in CDerived. Does anybody has an idea why?

    class CBase
    {
    public:
    int Get() const { int i; Get(i); return i;};
    virtual bool Get(int& i) const { return false; }
    };

    class CDerived : public CBase
    {
    int j;
    public:
    virtual bool Get(int& i) const { i = j; return true; }
    };

    void WTF()
    {
    CDerived d;
    int test = d.Get(); // error 2660: function does not take 0 arguments
    // int test = d.CBase::Get(); works, but yuck!

    CBase b;
    test = b.Get(); // OK.
    }


    Thanks,
    Goran,
     
    Goran, Sep 12, 2006
    #1
    1. Advertising

  2. Goran wrote:
    > Hi all!
    >
    > Example here doesn't compile in both VC++ and gcc. It's like Get(int&)
    > somehow hides Get() in CDerived. Does anybody has an idea why?
    >
    > class CBase
    > {
    > public:
    > int Get() const { int i; Get(i); return i;};
    > virtual bool Get(int& i) const { return false; }
    > };
    >
    > class CDerived : public CBase
    > {
    > int j;
    > public:
    > virtual bool Get(int& i) const { i = j; return true; }
    > };
    >
    > void WTF()
    > {
    > CDerived d;
    > int test = d.Get(); // error 2660: function does not take 0 arguments
    > // int test = d.CBase::Get(); works, but yuck!
    >
    > CBase b;
    > test = b.Get(); // OK.
    > }
    >
    >
    > Thanks,
    > Goran,
    >

    I'm not sure but I think when you redefine Get in CDerived for int
    parameter, you're hiding Get().
    I think it's due to:
    http://www.parashift.com/c -faq-lite/strange-inheritance.html#faq-23.9
     
    Carlos Martinez, Sep 12, 2006
    #2
    1. Advertising

  3. Goran

    Gavin Deane Guest

    Goran wrote:
    > Hi all!
    >
    > Example here doesn't compile in both VC++ and gcc. It's like Get(int&)
    > somehow hides Get() in CDerived.


    It's like Get(int&) somehow hides Get() because that's exactly what
    does happen.

    > Does anybody has an idea why?


    Why is because that's what the language rules say. This section of the
    FAQ

    http://www.parashift.com/c -faq-lite/strange-inheritance.html

    should show you ways round the problem.

    <snip code>

    Gavin Deane
     
    Gavin Deane, Sep 12, 2006
    #3
    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. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    910
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,999
    Smokey Grindel
    Dec 2, 2006
  3. C__chp
    Replies:
    4
    Views:
    510
    Puppet_Sock
    Feb 15, 2008
  4. George Hester

    Try over here likely more to the point here

    George Hester, Sep 30, 2004, in forum: Javascript
    Replies:
    0
    Views:
    113
    George Hester
    Sep 30, 2004
  5. FAQ server
    Replies:
    0
    Views:
    158
    FAQ server
    Aug 10, 2006
Loading...

Share This Page