Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



inheritence in c++


Posted Date: 30 Apr 2008    Resource Type: Articles/Knowledge Sharing    Category: Education

Posted By: mohit       Member Level: Gold
Rating:     Points: 5



C++ Inheritance
Inheritance is a way of relating two classes so that one class may use another class's members without redefining them (another way is using the friend declaration). A class may be derived from a base class by using the inheritance syntax:


class base { ... };
class derived : base { ... };
In fact if this done as above, all the members of the class base become private in the class derived, so it is better to use public inheritance:

class base { ... };
class derived : public base { ... };
In this way, all the members, whether data or functions, of base retain their access control category: public members become public, private members remain private. The rules of scope still apply, however, so that function members of the derived class cannot access the inherited members directly, unless the base class declares them to protected ( or public). In the example below, the class derived contains a member function accessP that accesses a data member dm1 of the class base, from which it inherits dm1. If the access control of dm1 was private then the function accessP would not compile. It would work for public access, but rather than open up access to users of the class, the protected keyword laves the member private, execept for derived classes: a useful convenience for programmers.


class base {
protected:
int dm1;
...
};


class derived: public base {
...
public:
void accessP() { ... dm1 ... }
...
};
Inheritance makes two new types which can be used separately, if necessary. However, more common is to use them as sub- and super-type.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: function scope in c++
Previous Resource: polymorphism in c++
Return to Discussion Resource Index
Post New Resource
Category: Education


Post resources and earn money!
 
Related Resources



Watch TV Channels
  • Watch Asianet TV online
  • Kairali TV in Internet
  • Surya TV online
  • Amritha TV Channel

  • Contact Us    Privacy Policy    Terms Of Use   

    SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.