C++ Primer 4th Edition errata?

  • Follow


I can't find this anywhere on the web.  I've tried e-mailing Barbara
Moo, but my message is blocked.  Can anyone tell me where I can find
it?

I'm confused by section 15.5.4.  Is it possible to call Base::fcn()
through a pointer to D1?  The text on p594 says this is not possible,
but the code on p595 says that this is OK.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply studennett (5) 8/24/2006 1:28:52 PM

"studennett" wrote
> I can't find this anywhere on the web.  I've tried e-mailing Barbara
> Moo, but my message is blocked.  Can anyone tell me where I can find
> it?
>
> I'm confused by section 15.5.4.  Is it possible to call Base::fcn()
> through a pointer to D1?  The text on p594 says this is not possible,
> but the code on p595 says that this is OK.

class Base
{
public:
   virtual int fcn();
};

class D1 : public Base
{
public:
  int fcn(int);
};

Base::fcn() { std::cout << "Base" << std::endl; return 0; }
Derived::fcn(int) { std::cout << "Derived" << std::endl; return 1;}

void main()
{
  D1 d;
  Base *p1 = &d;
  D1 *p2 = &d;

  int i = p1->fcn();  //output: Base
  int j = p2->fcn(2);  //output: Derived
  int k = p2->fcn();   // compiler error
// Error: function call [Derived.fcn()] does not match Derived::fcn(int)
}

I think 15.5.4 is saying it is not possible to call Base::fcn() from a
pointer to a D1 object when the pointer is of type D1*, but it is possible
when the pointer is of type Base*.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Marlene 8/29/2006 3:37:40 PM


1 Replies
266 Views

(page loaded in 0.091 seconds)

Similiar Articles:













7/20/2012 1:02:08 PM


Reply: