From: RB on
I have noticed some things (for sometime now) that I did not run across when I first
read about C++ nor do I think I really understand them. Could someone please
explain the differences (or definitions ) of these. Would really appreciate this.

What is a SuperClass (is this like a base class ? )
What is a SubClass (is this like a derived class ?
What is a nested class ( is this what I used to know as Composition of a class ? )

And exactly what is being compiled when (in the VStudio Class wizard ) when I
create a resource control variable of category "Control" and of type "DerivedClass"
and the Control is owned by the FormViewClass? I.e. the DerivedClass has a function
that is replacing the resource control's Base Class function but the resource control is
owned by the FormViewClass or it's window ?. The generated code looks like this
in the FormViewClass header file there is:

#include "DerivedClass.h" // docs said to add the derived class include here and in fact it
// does not work without it, but causes sbrowser to act strange

class FormViewClass : public CFormView
{
............<cut out >.............
public:
//{{AFX_DATA(CTry_1View) // This all class wizard generate stuff
enum { IDD = IDD_TRY_1_FORM };
DerivedClass m_FormListBoxObj; //<-this is the resource controls varible of category "Control"
//}}AFX_DATA // and of type "derivedClass"
// End of class wizard stuff,
In my FormViewClass .cpp file I have the following code
nIndex = m_FormListBoxObj.AddString(str); and if I hold my cursore over the
varible m_FormListBoxObj it says the following
DerivedClass FormViewClass : : ListBoxObj
which means the m_FormListBoxObj is a (exactly what ? ) of CTry_1View class
but it is ( being handled ??? ) by a function in DerivedClass class.
In other words I have this code working and I understand what I did to create it but as
far as C++ goes I don't really understand what it all is.


From: Scott McPhillips [MVP] on
"RB" <NoMail(a)NoSpam> wrote in message
news:%23$24wndsKHA.4652(a)TK2MSFTNGP02.phx.gbl...
> And exactly what is being compiled when (in the VStudio Class wizard )
> when I
> create a resource control variable of category "Control" and of type
> "DerivedClass"
> and the Control is owned by the FormViewClass? I.e. the DerivedClass has a
> function
> that is replacing the resource control's Base Class function but the
> resource control is
> owned by the FormViewClass or it's window ?

When you add a control variable the class wizard adds a line like this in
DoDataExchange

DDX_Control(pDX, IDC_LB_TOSEND, m_FormListBoxObj);

and this gets called during the dialog or formview initialization. This
line is responsible for all the magic. MFC is working hard for you to make
this happen. It intercepts all messages sent to the control, and passes
them to your derived class message map. If you don't add a handler for a
message, and/or if you handle it and call the base class, then the message
is passed on to the control's built in code. This lets you modify the
standard behavior of the control. The technique is called "subclassing" of
the control, a Windows term that has nothing to do with C++ classes. It's
done by hooking messages before they get to the control's code.

--
Scott McPhillips [VC++ MVP]

From: Joseph M. Newcomer on
See below...
On Fri, 19 Feb 2010 22:08:00 -0500, "RB" <NoMail(a)NoSpam> wrote:

>I have noticed some things (for sometime now) that I did not run across when I first
>read about C++ nor do I think I really understand them. Could someone please
>explain the differences (or definitions ) of these. Would really appreciate this.
>
>What is a SuperClass (is this like a base class ? )
>What is a SubClass (is this like a derived class ?
>What is a nested class ( is this what I used to know as Composition of a class ? )
****
Consider the following sequence:

class A { ...}
class B: public A {...}
class C: public A {...}

class B1: public B {...}
class B1_2 : public B1 {...}

We have the following relationships

A is a base class (does not depend on any other class)
B is a derived class. It is a subclass of A. A is a superclass of B
C is a derived class. It is a subclass of A. A is a superclass of C

B1 is a derived class. It is a subclass of B. B is a superclass of B1, and A is also a
superclass of B1. B is the direct superclass.

B1_2 is a derived class. It is a subclass of B1. B1 is a superclass of B1_2. B is also
a superclass of B1_2, and A is a superclass of B1_2. B1_2 is a subclass of B. B1_2 is a
subclass of A.

"subclass" and "superclass" represent a parent-child relationship.

Consider the following:

class X {
class Y { void Something(); ...};
...
};

Y is a nested class of X. To get the impelementation of Something, you would define it as

void X:Y:Something()
{
...
}
joe

>
>And exactly what is being compiled when (in the VStudio Class wizard ) when I
>create a resource control variable of category "Control" and of type "DerivedClass"
>and the Control is owned by the FormViewClass?
****
The type is DerivedClass. The variable is an instance of DerivedClass. The variable is a
member of the FormViewClass.
****
>I.e. the DerivedClass has a function
>that is replacing the resource control's Base Class function but the resource control is
>owned by the FormViewClass or it's window ?. The generated code looks like this
>in the FormViewClass header file there is:
>
>#include "DerivedClass.h" // docs said to add the derived class include here and in fact it
> // does not work without it, but causes sbrowser to act strange
****
I wouldn't trust the browser as far as I could throw it. The declaration of the #include
is essential. if the browser acts strange, that is a bug. Report it.
****
>
>class FormViewClass : public CFormView
>{
>...........<cut out >.............
>public:
> //{{AFX_DATA(CTry_1View) // This all class wizard generate stuff
> enum { IDD = IDD_TRY_1_FORM };
> DerivedClass m_FormListBoxObj; //<-this is the resource controls varible of category "Control"
> //}}AFX_DATA // and of type "derivedClass"
>// End of class wizard stuff,
>In my FormViewClass .cpp file I have the following code
>nIndex = m_FormListBoxObj.AddString(str); and if I hold my cursore over the
>varible m_FormListBoxObj it says the following
> DerivedClass FormViewClass : : ListBoxObj
>which means the m_FormListBoxObj is a (exactly what ? ) of CTry_1View class
>but it is ( being handled ??? ) by a function in DerivedClass class.
****
I tend to assume that if Intellinonsense says something that makes no sense, this is par
for the course. So I wouldn't place much reliance on what it says. If it works, it's
fine, but if it doesn't work, don't be surprised.

The variable DerivedClass is a member of the FormViewClass, but you have not indicated
what class the DerivedClass is derived from. So I don't know how to interpret the output.

Trust The Source, Luke.

Which means, no matter what Intellinonsense says, the one-and-only truth is that it is
what the compiler sees that matters.
>In other words I have this code working and I understand what I did to create it but as
>far as C++ goes I don't really understand what it all is.
****
I think you understand it, but might be confused by what Intellinonsense says. What you
have is a variable, of a certain type, inside a certain class. That is not an embedded
class, it is simply a variable with a type. Nothing more. The header file is required
because the compiler cannot compile the code unless it knows the type of the variable. So
that's why the #include is necessary. All you have is (reduced to essentials):

class DerivedClass : public SomeOtherClass {...};
class FormViewClass : public CFormView {
DerivedClass m_FormListBoxObj;
};

joe
****
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: RB on
Congratulations on your MVP award and
thank you for the very extensive and detailed reply.
So in summation:
A SuperClass is a base class
and aSubClass is a derived class
and a nested class is a Class inside of another class
If I read your reply correctly these are just new words for old things

And as to the MFC control category variable:

>"Joseph M. Newcomer" wrote in message
> The type is DerivedClass. The variable is an instance of DerivedClass.
>The variable is a member of the FormViewClass.
> ****

(please correct me if I misunderstood you )
So ..... the control category variable actually creates an instance of a Class object
of the type ( DerivedClass ) ? (or the control Base class if you did not use a derived one)
This is kinda what I felt it was doing in my gut, and is why I named it
" m_FormListBoxObj " or is my gut still leading me to misunderstand your reply?

>"Joseph M. Newcomer" wrote in message
>>#include "DerivedClass.h" // docs said to add the derived class include here and in fact it
>> // does not work without it, but causes sbrowser to act strange
> ****
> I wouldn't trust the browser as far as I could throw it. The declaration of the #include
> is essential. if the browser acts strange, that is a bug. Report it.

Ok I'm glad I do have that right since the sbrowser was making feel I had done something
wrong. The sbrowser has always performed as expected in the past, I'm not sure reporting
a bug would do any good since I use Visual C Pro. ver 6.0 which I doubt if they write fixes
for it anymore. I did all the updates for it already. It has served me well over the years for
what I do.

and also

>"Joseph M. Newcomer" wrote in message
> I tend to assume that if Intellinonsense says something that makes no sense,
> < cut out >So I wouldn't place much reliance on what it says.
>
> The variable DerivedClass is a member of the FormViewClass, but you have not indicated
> what class the DerivedClass is derived from. So I don't know how to interpret the output.

DerivedClass was from the base class of CListBox and so then ....

> All you have is (reduced to essentials):
> class DerivedClass : public SomeOtherClass {...};
> class FormViewClass : public CFormView {
> DerivedClass m_FormListBoxObj;

Well if the DerivedClass is a member of the FormViewClass then ......
Am I correct in ascertaining that the DerivedClass is nested inside of my FormViewClass ?
so that in C++ it would be like FormViewClass : DerivedClass : m_FormListBoxObj ?

I thank you again, and even if I misunderstood some of your excellent answers I believe
I am of a better understanding and will now go back and read some bibliographies over
again. RB


From: Ajay Kalra on
> So in summation:
> A SuperClass is a base class
> and aSubClass is a derived class


Thats too simplistic and breaks down in cases like this:

class A{};
class B : class A{}
class C: class B{}

Here class B is superclass of C as well subclass of A.

--
Ajay