Click here to Skip to main content
15,911,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Member 24341328-Dec-04 16:04
Member 24341328-Dec-04 16:04 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Alok Bhardwaj29-Dec-04 19:16
Alok Bhardwaj29-Dec-04 19:16 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Alok Bhardwaj29-Dec-04 19:35
Alok Bhardwaj29-Dec-04 19:35 
QuestionHow to prevent from inhertance Pin
Kiran Kumar Singani28-Dec-04 0:26
Kiran Kumar Singani28-Dec-04 0:26 
AnswerRe: How to prevent from inhertance Pin
Prakash Nadar28-Dec-04 0:34
Prakash Nadar28-Dec-04 0:34 
GeneralRe: How to prevent from inhertance Pin
virtualkirankumar28-Dec-04 0:40
virtualkirankumar28-Dec-04 0:40 
GeneralRe: How to prevent from inhertance Pin
Prakash Nadar28-Dec-04 0:46
Prakash Nadar28-Dec-04 0:46 
AnswerRe: How to prevent from inhertance Pin
jan larsen28-Dec-04 1:39
jan larsen28-Dec-04 1:39 
As Prakash says, there is no keyword for this. But there is a method for getting the same kind of encapsulation.
First you declare the interface for you class in a cpp file, then you declare an implementing class in a header file.
Here's a small example:

The header file dclares the interface Public, and a function that creates an instance:
<span style="color: green;">// The header file tester.h</span>
<span style="color: blue;">#ifndef</span> _TESTER_H_
<span style="color: blue;">#define</span> _TESTER_H_
<br> <br>

<span style="color: green;">// The interface definition:</span>
<span style="color: blue;">class</span> Public
{
<span style="color: blue;">public</span>:
	<span style="color: blue;">virtual int</span> GetX() = 0;
};
<br> <br>
<span style="color: green;">// This function returns a pointer to an instance of an implementing class.</span>
Public * CreatePublic(<span style="color: blue;">int</span> x);
<br> <br>
<span style="color: blue;">#endif</span> // _TESTER_H_


The cpp file declares the implementing class Private:
<span style="color: green;">// The cpp file tester.cpp</span>
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: green;">// The implementing class.</span>
<span style="color: blue;">class</span> Private: <span style="color: blue;">public</span> Public
{
<span style="color: blue;">public</span>:

	Private(<span style="color: blue;">int</span> x): m_x(x)
	{

	}
<br> <br>
	<span style="color: blue;">int</span> GetX()
	{
		return m_x;
	}
<br> <br>
<span style="color: blue;">private</span>:
	<span style="color: blue;">int</span>		m_x;
};
<br> <br>
Public * CreatePublic(<span style="color: blue;">int</span> x)
{
	return new Private(x);
}


Here's how to use it:
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: blue;">int</span> main()
{
	<span style="color: green;">// Can't do this because Private is declared in the header file.</span>
	<span style="color: green;">//Private  priv = new Private(2);</span>
<br> <br>
	Public * pPub = CreatePublic(42);

	<span style="color: blue;">delete</span> pPub;
<br> <br>
	<span style="color: blue;">return</span> 0;
}


The funny thing is, that while the Java keyword final optimizes the code by removing the need for a vtable, this C++ technique adds an overlay by creating a vtable.

"After all it's just text at the end of the day. - Colin Davies

"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

AnswerRe: How to prevent from inhertance Pin
CP Visitor28-Dec-04 2:34
CP Visitor28-Dec-04 2:34 
GeneralSmall Prolem with OptionTree Pin
Fenderman27-Dec-04 23:33
Fenderman27-Dec-04 23:33 
GeneralRe: Small Prolem with OptionTree Pin
Prakash Nadar27-Dec-04 23:48
Prakash Nadar27-Dec-04 23:48 
GeneralRe: Small Prolem with OptionTree Pin
Fenderman28-Dec-04 0:17
Fenderman28-Dec-04 0:17 
GeneralRe: Block Copying Data Pin
Prakash Nadar27-Dec-04 23:46
Prakash Nadar27-Dec-04 23:46 
GeneralHm... Pin
Dennis Gourjii27-Dec-04 23:47
Dennis Gourjii27-Dec-04 23:47 
QuestionHow To Get Known of disconnection Pin
Rassul Yunussov27-Dec-04 21:42
Rassul Yunussov27-Dec-04 21:42 
GeneralTCPView Pin
Anonymous27-Dec-04 21:39
Anonymous27-Dec-04 21:39 
Questionhow can i get network ip address Pin
vc-programmer-27-Dec-04 20:59
vc-programmer-27-Dec-04 20:59 
AnswerRe: how can i get network ip address Pin
David Crow28-Dec-04 3:27
David Crow28-Dec-04 3:27 
GeneralRe: ReadFile, WriteFile in Console application Pin
Prakash Nadar27-Dec-04 20:08
Prakash Nadar27-Dec-04 20:08 
GeneralMemory leaks and VCRT Pin
Imtiaz Murtaza27-Dec-04 17:55
Imtiaz Murtaza27-Dec-04 17:55 
GeneralRe: Memory leaks and VCRT Pin
virtualkirankumar28-Dec-04 0:19
virtualkirankumar28-Dec-04 0:19 
GeneralRe: Memory leaks and VCRT Pin
Kiran Kumar Singani28-Dec-04 0:21
Kiran Kumar Singani28-Dec-04 0:21 
GeneralRe: Memory leaks and VCRT Pin
vishalmore28-Dec-04 4:15
vishalmore28-Dec-04 4:15 
GeneralRe: Memory leaks and VCRT Pin
Henry miller28-Dec-04 4:20
Henry miller28-Dec-04 4:20 
GeneralHelp! in C++ How to implement 2 classes share one class Pin
stans8027-Dec-04 15:04
stans8027-Dec-04 15:04 

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.