Click here to Skip to main content
15,890,690 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: why private virtual function? Pin
Maximilien15-Mar-08 7:15
Maximilien15-Mar-08 7:15 
GeneralRe: why private virtual function? Pin
George_George16-Mar-08 0:16
George_George16-Mar-08 0:16 
AnswerRe: why private virtual function? Pin
Nemanja Trifunovic15-Mar-08 4:38
Nemanja Trifunovic15-Mar-08 4:38 
GeneralRe: why private virtual function? Pin
_808615-Mar-08 7:25
_808615-Mar-08 7:25 
GeneralRe: why private virtual function? Pin
George_George16-Mar-08 0:13
George_George16-Mar-08 0:13 
GeneralRe: why private virtual function? Pin
_808617-Mar-08 6:42
_808617-Mar-08 6:42 
GeneralRe: why private virtual function? Pin
George_George16-Mar-08 0:05
George_George16-Mar-08 0:05 
AnswerRe: why private virtual function? Pin
Rajesh R Subramanian15-Mar-08 5:29
professionalRajesh R Subramanian15-Mar-08 5:29 
George_George wrote:
Why do we need to fine a virtual function as private?


The classic answer, because you don't want to expose everything to the world? Smile | :)

See this example:
class base
{
public:
	void Interface()
	{
                ///some code...
                //if( some expression is true)
		   Implementation();
                //else
                   //return;
                //some code...
	}
private:
	virtual void Implementation(void)
	{
		cout<<"Haha lol I am private - Base"<<endl;
	}
};

class der:public base
{
	void Implementation(void)
	{
		cout<<"I am private too - Derived"<<endl;
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	base bs;
	bs.Interface();
	//bs.Implementation(); //No way!

	der dr;
	dr.Interface();
	//dr.Implementation(); //No way, again! (Unless you keep it public)

	return 0;	
}



George_George wrote:
As special functions we can achieve and any special limitaitons?


Here, the virtual functions are visible down through the hierarchy to the child classes, but only the base would actually get to access it!

Please see this[^] and this one[^] too. Smile | :)


Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP

GeneralRe: why private virtual function? Pin
George_George16-Mar-08 0:12
George_George16-Mar-08 0:12 
QuestionHOW TO ADD PROJECT INTO WORKSPACE Pin
bala_potty15-Mar-08 1:54
bala_potty15-Mar-08 1:54 
Generalabout parameter passing Pin
savitri15-Mar-08 1:07
savitri15-Mar-08 1:07 
JokeRe: about parameter passing Pin
_808615-Mar-08 7:33
_808615-Mar-08 7:33 
GeneralRe: about parameter passing Pin
Rajkumar R15-Mar-08 10:44
Rajkumar R15-Mar-08 10:44 
GeneralRe: about parameter passing Pin
savitri16-Mar-08 21:46
savitri16-Mar-08 21:46 
GeneralRe: about parameter passing Pin
_808617-Mar-08 6:44
_808617-Mar-08 6:44 
GeneralRe: about parameter passing Pin
JudyL_MD17-Mar-08 7:35
JudyL_MD17-Mar-08 7:35 
GeneralRe: about parameter passing Pin
savitri17-Mar-08 20:02
savitri17-Mar-08 20:02 
Questioncan anybody tell me how to execute an exe from my application in vc++ Pin
philiptabraham15-Mar-08 0:28
philiptabraham15-Mar-08 0:28 
AnswerRe: can anybody tell me how to execute an exe from my application in vc++ Pin
Rajesh R Subramanian15-Mar-08 0:30
professionalRajesh R Subramanian15-Mar-08 0:30 
AnswerRe: can anybody tell me how to execute an exe from my application in vc++ Pin
Rajkumar R15-Mar-08 0:33
Rajkumar R15-Mar-08 0:33 
AnswerRe: can anybody tell me how to execute an exe from my application in vc++ Pin
David Crow15-Mar-08 4:34
David Crow15-Mar-08 4:34 
General[Message Deleted] Pin
Le@rner14-Mar-08 21:27
Le@rner14-Mar-08 21:27 
GeneralRe: help me its urgent. Pin
Rajkumar R15-Mar-08 0:07
Rajkumar R15-Mar-08 0:07 
GeneralRe: help me its urgent. Pin
Rajesh R Subramanian15-Mar-08 0:30
professionalRajesh R Subramanian15-Mar-08 0:30 
GeneralRe: help me its urgent. Pin
Paul Conrad15-Mar-08 12:55
professionalPaul Conrad15-Mar-08 12:55 

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.