MFC Inheritance

Why is it when you declare a class and derive it from a CWnd you can't create a new class of it because it can't access the protected members. The MFC Framework does all the work for you on it. I'm sure this is easy to understand.
Jack Adkins
[268 byte] By [left1none] at [2007-11-19 7:04:11]
# 1 Re: MFC Inheritance
Why is it when you declare a class and derive it from a CWnd you can't create a new class of it because it can't access the protected members.
You can't create a new class of what ?
Sahir at 2007-11-11 0:28:49 >
# 2 Re: MFC Inheritance
I'm sure this is easy to understand.
Actually no, you're not very clear.

Why is it when you declare a class and derive it from a CWnd you can't create a new class of it because it can't access the protected members. The MFC Framework does all the work for you on it.
You have derived a class from CWnd but the constructor accessor si protected so you cannot dynamically create an instance of the class? What stops you changing the accessor from protected to public?
cilu at 2007-11-11 0:29:46 >
# 3 Re: MFC Inheritance
Why is it when you declare a class and derive it from a CWnd you can't create a new class of it because it can't access the protected members. The MFC Framework does all the work for you on it. I'm sure this is easy to understand.

Jack Adkins
No it's not clear.
What protected members?
How did you derive from CWnd?
How did you try to instantiate/create (?) an object of derived class?
ovidiucucu at 2007-11-11 0:30:45 >
# 4 Re: MFC Inheritance
Sorry it wasn't very clear. I wrote it real late at night and very little sleep the night before. I know I can change it to public but it is set as protected for a reason. But let me give an example.

Say I declare a class and derive it from CMDIChildWnd. When I create an instance of the class it says it cannot access the protected function. Talking about the constructor. I usually just change the protected to public but was just curious why it's like that.

Jack
left1none at 2007-11-11 0:31:48 >
# 5 Re: MFC Inheritance
Usually the reason that you set a amember variable to protected is to force a programmer to only modify that variable in a member function of a class derrived from the base class or the member function of the base class its self.

You are asking for a very general kind of help. Why did a programmer do this? Well you have to take a common sense approach to this. Maybe he set to protected on accident and had an itch to scratch so he forgot to set it public or maybe not.

Why dont you supply some source code. Pref as little as possible. Even just use the code tags if you can.

ahoodin
ahoodin at 2007-11-11 0:32:44 >
# 6 Re: MFC Inheritance
It's not a general question. The question is why does MFC make the constructor and destructor protected when you derive your own CMDIChildWnd class. Then you can't access the class due to not being able to access the protected constructor. Now I know you can change it to public or create another constructor which is public but it doesn't make sense to me. Thanks for the replys.

Jack
left1none at 2007-11-11 0:33:45 >
# 7 Re: MFC Inheritance
The classess like CWinApp are created using Singleton design, ie only one instance of the Class can be instantiated by the application. Its why the constructors of this type of class who is considered as singleton classess is kept protected.
Vinod S at 2007-11-11 0:34:49 >