Re: [Dev-C++] protected and private in c++ classes
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2004-03-09 11:03:22
|
I don't think that is quite correct.
Without getting too nerdy, private specifies that the member variable or
method (methods are usually public, not private) can only be accessed by a
method of that class, and cannot be accessed directly.
So if I have a private member
int EmployeeID;
I cannot do
MyObject.EmployeeID = 12345;
Because it is private. What I need is a public method like this
void SetEmployeeID(int Num)
{
EmployeeID = Num;
}
Then I can do MyObject.SetEmployeeID(12345);
Protected means the members are public to that class, but if a class is
derived from it then they become private. e.g.
class Person
{
protected:
double DNASequence;
}
class Employee : public Person
{
// class Employee now has
// private :
// double DNASequence;
}
Let me know if any of this sounds wrong.
Daniel
>From: Per Westermark <pw...@ia...>
>To: studioartoni <stu...@li...>
>CC: Dev...@li...
>Subject: Re: [Dev-C++] protected and private in c++ classes
>Date: Tue, 9 Mar 2004 11:15:18 +0100 (CET)
>
>Private is only for methods of the class.
>
>Protected are also available to all inherriting classes.
>
>/Per W
>
>On Tue, 9 Mar 2004, studioartoni wrote:
>
> > Excuse the question,
> > but which is the difference between 'protected' and 'private' in c++
>classes?
> > Thank you.
> >
> >
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Find a cheaper internet access deal - choose one to suit you.
http://www.msn.co.uk/internetaccess
|