|
Prev: VC6 (was Re: C++0x (was: passing vector as argument))
Next: Best way for C# application to access VC application
From: PvdG42 on 30 Apr 2008 09:34 Standard C++ console application, using classes in an inheritance hierarchy. Does the VC++ compiler in VS 2005 enforce implementation of pure abstract functions declared in the base class, in derived classes? I was working on a classroom example and added a pure virtual function to the base class, expecting to see syntax errors appear because neither of two derived classes implemented the function, but a rebuild showed no errors. So, am I misinformed that pure virtual functions *must* be implemented in derived classes, or what are other possibilities. The compiler does catch it if I attempt to instantiate the (now) abstract base class, but nothing on the unimplemented pure virtual function. FWIW, no, this is not a homework assignment. TIA for any insights.
From: David Wilkinson on 30 Apr 2008 09:54 PvdG42 wrote: > Standard C++ console application, using classes in an inheritance > hierarchy. > Does the VC++ compiler in VS 2005 enforce implementation of pure > abstract functions declared in the base class, in derived classes? > I was working on a classroom example and added a pure virtual function > to the base class, expecting to see syntax errors appear because neither > of two derived classes implemented the function, but a rebuild showed no > errors. > So, am I misinformed that pure virtual functions *must* be implemented > in derived classes, or what are other possibilities. The compiler does > catch it if I attempt to instantiate the (now) abstract base class, but > nothing on the unimplemented pure virtual function. > > FWIW, no, this is not a homework assignment. PvdG42: You will not get errors if you do not instantiate these derived classes. But if you do, you should. I'm sure that VC does this correctly. Can you post an example? -- David Wilkinson Visual C++ MVP
From: PvdG42 on 30 Apr 2008 10:14
"David Wilkinson" <no-reply(a)effisols.com> wrote in message news:edO7rmsqIHA.420(a)TK2MSFTNGP02.phx.gbl... > PvdG42 wrote: >> Standard C++ console application, using classes in an inheritance >> hierarchy. >> Does the VC++ compiler in VS 2005 enforce implementation of pure abstract >> functions declared in the base class, in derived classes? >> I was working on a classroom example and added a pure virtual function to >> the base class, expecting to see syntax errors appear because neither of >> two derived classes implemented the function, but a rebuild showed no >> errors. >> So, am I misinformed that pure virtual functions *must* be implemented in >> derived classes, or what are other possibilities. The compiler does catch >> it if I attempt to instantiate the (now) abstract base class, but nothing >> on the unimplemented pure virtual function. >> >> FWIW, no, this is not a homework assignment. > > PvdG42: > > You will not get errors if you do not instantiate these derived classes. > But if you do, you should. I'm sure that VC does this correctly. > > Can you post an example? > > -- > David Wilkinson > Visual C++ MVP Arrrrgh! How silly of me. When I was doing this last night, I must have been out on my feet. The demo program I used *did not* instantiate the derived classes. Adding instantiation statements shows the errors. Doh! Thanks very much for setting me straight ;-) |