Posted on July 11, 2013. Filed under: C++ |

Same as Java concept, C++ allow inheritance, with slightly different syntax.
class Mother{
int publicv;
int protectedv;
int privatev;

//class Daughter inherit all the public and protected variables and methods from class Mother
class Daughter: public Mother { }

#include “Mother.h” //has to come before #include “Daughter.h”
#include “Daughter.h”
using namespace std;

void Daughter::doSomething(){
publicv = 1;
protectedv = 1;
//no access to privatev


Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: