473,320 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting confused in Virtual calls

Hi all

if I have the public function in the class which has the key word
virtual i.e

public:
virtual void SetControls();

Then what does this really mean in the program.

Thanks In Advance
Priya

Dec 15 '05 #1
6 1114

Priya Mishra wrote:
Hi all

if I have the public function in the class which has the key word
virtual i.e

public:
virtual void SetControls();

Then what does this really mean in the program.


dynamic binding.
http://www.parashift.com/c++-faq-lit...functions.html

Dec 15 '05 #2
Priya Mishra wrote:
Hi all

if I have the public function in the class which has the key word
virtual i.e

public:
virtual void SetControls();

Then what does this really mean in the program.

Thanks In Advance
Priya


The virtual keyword allows you to define an entire different function
with the same name and parameters(arguments) in a derived class. In
your program SetControls can be defined in a derived class with same
signature (same parameters and return values). Please get a good book
and read it.

Cheers
Shan

Dec 15 '05 #3
The virtual keyword allows you to define an entire different function
with the same name and parameters(arguments) in a derived class.


You can do this without the "virtual" keyword also, but you don't get
dynamic binding.

#include <iostream>

class Base
{
public:
int foo() { std::cout << "in Base::foo()" << std::endl; }
};

class Derived : public Base
{
public:
int foo() { std::cout << "in Derived::foo()" << std::endl; }
};

int main()
{
Base * bp = new Derived();

// no polymorphism because Base::foo() isn't virtual
bp->foo();

return 1;
}

Dec 15 '05 #4
On 2005-12-15, Priya Mishra <mi*******@gmail.com> wrote:
Hi all

if I have the public function in the class which has the key word
virtual i.e

public:
virtual void SetControls();

Then what does this really mean in the program.


It means that this class provides a function that may vary
polymorphically for its derived classes, in other words, derived
classes may override the function with their own implementation.
In addition, it promises to provide a default implementation that
derived classes can use if they don't want to override it.

--
Neil Cerutti
Dec 15 '05 #5

Neil Cerutti wrote:
On 2005-12-15, Priya Mishra <mi*******@gmail.com> wrote:
virtual void SetControls();

Then what does this really mean in the program.


In addition, it promises to provide a default implementation that
derived classes can use if they don't want to override it.


The original post asked what "virtual" means. A member function can be
virtual and still not provide a default implementation.

Dec 15 '05 #6
On 2005-12-15, BigBrian <wo**@brianmielke.com> wrote:

Neil Cerutti wrote:
On 2005-12-15, Priya Mishra <mi*******@gmail.com> wrote:
> virtual void SetControls();
>
> Then what does this really mean in the program.


In addition, it promises to provide a default implementation
that derived classes can use if they don't want to override
it.


The original post asked what "virtual" means. A member
function can be virtual and still not provide a default
implementation.


Yes, but not that specific function. ;-)

--
Neil Cerutti
Dec 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Roy Yao | last post by:
Hello, I need to pass a pointer to a callback function to the lower level modules. But the function is thought to be a virtual member one. How can I get the real address of the virtual...
8
by: Just D | last post by:
All, What are advantages and disadvantages of these two different approaches? 1 . I create a base class with a few virtual methods, then I derive my classes from this class, override these...
18
by: nenad | last post by:
Wouldn't it be nice if we could do something like this: class Funky{ public: auto virtual void doStuff(){ // dostuff } };
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
15
by: Heiner | last post by:
#include <stdio.h> class A { public: virtual A & operator= (const A &); virtual void test(const A &); }; class B : public A
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
4
by: archimed7592 | last post by:
Hi. for example i have base class A and dirved class B: struct A { virtual void f() { std::cout << "A::f()" << std::endl; } }; struct B : public A {
5
by: Ned White | last post by:
I have set up a virtual directory on ISS 6.0 to store the all .jpg and .swf files which i use in my project It is alias name is "OutSrc" Is it possible to acquire a list of files which exist in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.