Click here to Skip to main content
15,913,685 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralApplictions Communication problem Pin
ReBeL34716-Mar-05 19:47
ReBeL34716-Mar-05 19:47 
GeneralRe: Applictions Communication problem Pin
John R. Shaw17-Mar-05 6:58
John R. Shaw17-Mar-05 6:58 
GeneralGetCurrentHwProfile( ) api usage Pin
brilliant10116-Mar-05 19:21
brilliant10116-Mar-05 19:21 
GeneralProblem with Multiple Instances of ActiveX Control, Please Help Pin
rdeekonda16-Mar-05 18:27
rdeekonda16-Mar-05 18:27 
GeneralHelp on Compiled HTML(CHM) Viewer Pin
anukrati16-Mar-05 18:13
anukrati16-Mar-05 18:13 
GeneralFrame comparison Pin
Francis Chau16-Mar-05 17:12
Francis Chau16-Mar-05 17:12 
Generalvirutal class and friend class Pin
phijophlip16-Mar-05 17:10
phijophlip16-Mar-05 17:10 
GeneralRe: virutal class and friend class Pin
HalfWayMan16-Mar-05 22:32
HalfWayMan16-Mar-05 22:32 
A breif and sketchy answer.

Friend Class:

Take the following simple class:

class A
{
private:
int a, b;
public:
A() : a (0), b (0) { }
};

This class has two private data members. Private means that only methods from that class can access them. Now, say you had anouther class called B that wanted to access those data members. How do you do that without making the members public? Define class B as a friend of class A. Such as this:

class A
{
private:
int a, b;
public:
A () : a(0), b (0) {}
friend class B;
};

class B
{
public:
A Other;
int i;

B()
{
i = Other.a + Other.b;
}
};

You can also have other friends, not just classes. Just remember that only you and your friends are allowed to see your private parts. (lame joke, sorry).

Virtual Classes:

This is slightly more complex. A virtual class is where you define a member function of a class as virtual, which means that if you define anouther class that inherits from that one, it can override that virtual function. If it overrides that function (declaration is identical) then that function is called. If it does not, then the parent classes function is called instead. An example:

class A
{
public:
void Func1 ();
virtual void Func2 ();
};

class B : public A
{
public:
void Func3 ();
virtual void Func2 ();
};

Now, instantiate and object of class B:

B MyVar;

MyVar.Func3 () will call the function "Func3" in class B.
MyVar.Func2 () will call the function "Func2" in class B;

But, if the "virtual void Func2 ()" was missing from class B:

MyVar.Func2 () will call the function "Func2" in class A;

So basically "virtual" means that the function can be overriden.

Anouther use of virtual is a pure-virtual function. That means that it has NO function body, and is just used to define a form for the class. To use the above example:

class A
{
public:
void Func1 ();
virtual void Func2 () = 0;
};

class B : public A
{
public:
void Func3 ();
virtual void Func2 ();
};

Now, if we try and instantiate an object of class A:

A MyVar1;

The compiler will die and say something along the lines of "You cannot instantiate a class with a pure virtual member".

But, we CAN instantiate class B:

B MyVar;

This is really only useful for enforcing functionality in a class.

These are really loose, not too detailed.

Yours,
Blake.
Generaldifference between virutal class and friend class Pin
phijophlip16-Mar-05 17:10
phijophlip16-Mar-05 17:10 
GeneralRe: difference between virutal class and friend class Pin
ThatsAlok16-Mar-05 18:08
ThatsAlok16-Mar-05 18:08 
GeneralRe: difference between virutal class and friend class Pin
toxcct16-Mar-05 21:31
toxcct16-Mar-05 21:31 
GeneralCreating a graph chart Pin
Anonymous16-Mar-05 16:48
Anonymous16-Mar-05 16:48 
GeneralCompilation errors in Debug mode Pin
Gagnon Claude16-Mar-05 16:35
Gagnon Claude16-Mar-05 16:35 
GeneralRe: Compilation errors in Debug mode Pin
toxcct16-Mar-05 21:11
toxcct16-Mar-05 21:11 
Generaldrop down scroll bar too small Pin
catdude16-Mar-05 16:33
catdude16-Mar-05 16:33 
GeneralRe: drop down scroll bar too small Pin
Roger Allen17-Mar-05 0:07
Roger Allen17-Mar-05 0:07 
GeneralRe: drop down scroll bar too small Pin
catdude17-Mar-05 2:07
catdude17-Mar-05 2:07 
GeneralDetecting mouse clicks outside my dialog Pin
djtommye16-Mar-05 15:59
djtommye16-Mar-05 15:59 
GeneralRe: Detecting mouse clicks outside my dialog Pin
namaskaaram16-Mar-05 19:51
namaskaaram16-Mar-05 19:51 
GeneralRe: Detecting mouse clicks outside my dialog Pin
djtommye17-Mar-05 19:26
djtommye17-Mar-05 19:26 
GeneralRe: Detecting mouse clicks outside my dialog Pin
namaskaaram17-Mar-05 19:51
namaskaaram17-Mar-05 19:51 
GeneralVS6 and Inline Assembly Pin
quantum6916-Mar-05 15:58
quantum6916-Mar-05 15:58 
GeneralRe: VS6 and Inline Assembly Pin
David Crow17-Mar-05 3:24
David Crow17-Mar-05 3:24 
GeneralRe: VS6 and Inline Assembly Pin
John R. Shaw17-Mar-05 7:21
John R. Shaw17-Mar-05 7:21 
GeneralRe: VS6 and Inline Assembly Pin
quantum6917-Mar-05 15:29
quantum6917-Mar-05 15:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.