Re: [Dev-C++] Conditions to Use Virtual Functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: matheus r. <mfr...@gm...> - 2007-08-02 14:54:32
|
The first use I see is when developing interfaces, a class with pure virtual
functions. The classic example is the Shape interface, with its draw method.
Then, classes like Rectangle, Triangles etc can implement this method. And
in a loop, you could have a vector of Shapes (sv), and something like this
to draw all shapes:
for_each(sv.begin(), sv.end(), std::mem_fun(&Shape::draw));
Also, many times a child class add functionality to an object. For example,
a MoverClass may have the function move as a member, which updates its
position. An AircraftClass might want to override this move function, to
update its aerodynamic data to, like this:
void AircraftClass::move(){
MoverClass::move();
// update aero data
}
My 2 cents.
2 Aug 2007 12:41:31 -0000, Peeyush Bishnoi <pee...@re...>:
>
>
> Hello All ,
>
> I have one very simple & important query.
> I want to know the conditions & circumstances when to use the Virtual
> Function in a Project.
>
> I know most of the thing about the Virtual Function like it is used to
> implement Run type Polymorphism , Virtual Function VTBL & VPTR etc. , but
> still i get confused how & when it is needed in a Project , & in what
> circumstances & condition should i used.
>
> Please feed me through the valuable suggestions.
>
> Thank you ,
>
>
> Regards
> Peeyush
>
>
> [image: select view apply]<http://adworks.rediff.com/cgi-bin/AdWorks/click.cgi/www.rediff.com/signature-home.htm/1050715198@Middle5/1307758_1301384/1307141/1?PARTNER=3&OAS_QUERY=null+target=new+>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
|