Calling base class's method from Main

Hi,
I have this base class:
1
2
3
4
5
6
7
8
Class Base
{
  public:  
   virtual uchar ReadByte(uchar addr) {//read value at base_addr + addr};
 
  private:
    uchar base_addr;
}


and this class
1
2
3
4
5
6
class Derived: public Base
{
  public:
    Derived();
    uchar ReadByte(uchar addr) {//read value at 3000 + addr};
}


Derived class's constructor is defined as:
Derived::Derived() : Base(100)

In other words, if I call Base's ReadByte function, it reads the value at 100+whatever value is passed in, versus if I call Derive's ReadByte function, it read the value at 3000+value passed.

I know if I want to use Base's functions within Derived class, I can do Base::function(). But what about outside of Derived?

I have:
1
2
3
4
5
int main()
{
  Derived d;
  d.Base::ReadByte(2);
}


And this does not seem to work for me. But if I just take out whatever code was actually in Base::ReadByte() and put them in main directly, then I get the right value. So I know the statements themselves are correct, but my method of invoking Base's method is wrong?

Please help!

Thanks!!
Topic archived. No new replies allowed.