Why compilation error here?

G

Goran

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,
 
C

Carlos Martinez

Goran said:
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
 
G

Gavin Deane

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top