LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-01-2002, 05:04 PM   #1
Cyth
Member
 
Registered: Mar 2001
Location: Sweden, Lund
Distribution: Slackware
Posts: 68

Rep: Reputation: 15
Virtual void


Hi all,

What does "virtual void" mean?

I'm trying to do some basic qt/KDE programming..

Yes I know, this isn't the programming forum.

best regards,
Cyth
 
Old 01-01-2002, 11:49 PM   #2
concoran
Member
 
Registered: Jun 2001
Location: 28N,82W
Distribution: XP,Ubuntu 9
Posts: 473

Rep: Reputation: 30
Please ask this question in the 'Programming' section

virtual specifies the function type.
void is a datatype,
eg.

class myclass
{
public:
virtual void Func(){}
};
 
Old 01-02-2002, 12:18 AM   #3
taz.devil
Senior Member
 
Registered: Nov 2001
Location: Wa. State
Distribution: Slackware
Posts: 1,261

Rep: Reputation: 45
Re: Virtual void

Quote:
Originally posted by Cyth
Hi all,

What does "virtual void" mean?

I'm trying to do some basic qt/KDE programming..

Yes I know, this isn't the programming forum.

best regards,
Cyth
It means you've written yourself into an unyielding black hole of code in which escape is unachievable!
 
Old 01-02-2002, 01:15 AM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Re: Virtual void

Quote:
Originally posted by Cyth
What does "virtual void" mean?

I'm trying to do some basic qt/KDE programming..

Yes I know, this isn't the programming forum.
i like it when they don't realise their asking the question in the wrong forum..and don't admit it, it makes the person asking the question seem more intelligent.
 
Old 01-02-2002, 08:06 AM   #5
Cyth
Member
 
Registered: Mar 2001
Location: Sweden, Lund
Distribution: Slackware
Posts: 68

Original Poster
Rep: Reputation: 15
No, really; what does virtual mean?

/Cyth
 
Old 01-02-2002, 08:44 AM   #6
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
The virtual keyword is used to make a function virtual. If a class is derived from a base class with and the function is overwritten then if it's virtual then the function from the derived class will be run instead of the one from the base class.
That probably just sounds even more confusing because I'm not good at explaining these kind of things. If you want a full explanation try downloading the book Thinking in C++ from Bruce Eckel. In chapter 15 it has a complete explanation of virtual functions.

http://bruceeckel.com
 
Old 01-02-2002, 12:08 PM   #7
dean35970
LQ Newbie
 
Registered: Sep 2001
Location: Croatia
Distribution: Mandrake 9.0
Posts: 12

Rep: Reputation: 0
Smile

Here is the simple example of virtual function which is perhaps the easiest way to understand what it means.

class Foo {
public:
virtual void A;
};

class Foo1: public Foo {
public:
void A;
};

void Foo::A {
printf("\nHello world from Foo");
}

void Foo1::A {
printf("\nHello world from Foo1");
}

int main()
{
Foo *x = new Foo1();
x->A;
}

The result should be "Hello world from Foo1" even though we declared the x as Foo. This works only for the objects which are created on the heap (the new keyword). This concept is called polimorphism. By declaring function as virtual compiler calls the function from the subclass even though that pointer type is base class pointer. For more datailed information read some books.
 
Old 01-02-2002, 02:27 PM   #8
Cyth
Member
 
Registered: Mar 2001
Location: Sweden, Lund
Distribution: Slackware
Posts: 68

Original Poster
Rep: Reputation: 15
Thanks!

/Cyth
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
meaning of void* kpachopoulos Programming 3 10-12-2005 04:48 PM
void main(void) linuxanswer Programming 4 10-26-2003 12:37 AM
void? Patchorus Programming 9 10-25-2003 07:24 PM
void pointer help gonnaWorkItOut Programming 1 10-12-2003 11:52 AM
void foo(void) and void foo() lackluster Programming 9 02-15-2003 10:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration