answersLogoWhite

0

#include<iostream>

class base

{

int m_data;

public:

base(const int data):m_data(data){}

base(const base& cpy):m_data(cpy.m_data){}

base& operator=(const int rhs){m_data=rhs;return(*this);}

base& operator=(const base& rhs){m_data=rhs.m_data;return(*this);}

virtual ~base(){}

};

class derived

{

public:

derived(const int data):base(data){}

derived(const derived& cpy):base(cpy){}

derived& operator=(const int rhs){return(base::operator=(rhs));}

derived& operator=(const derived& rhs){return(base::operator=(rhs));}

virtual ~derived(){}

};

int main()

{

derived d=42;

}

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
JudyJudy
Simplicity is my specialty.
Chat with Judy
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao

Add your answer:

Earn +20 pts
Q: Program for derived class in cpp?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

CPP Program for Implementing Knuth-morris-pratt pattern matching algorithm?

what is the pure algorithm instead of cpp program?


How to print the code of a program in the output terminal when the program is being executed in cpp?

Such a program is called a Quine. http://en.wikipedia.org/wiki/Quine_(computing)


How do you access a base class method from a derived class in Cpp?

Use the scope resolution operator (::) to explicitly call the base class method. Note that the base class method must be protected or public in order for a derived class to access it. Private members are only accessible to the class itself and to friends of the class, regardless of whether the derivative uses public, protected or private inheritance. It is quite normal for a base class to provide a "default" implementation for a virtual method for which a derived class may override. Although the derived class will generally provide its own implementation of the method, it may also call the base class method either before, during or after performing its own implementation. The following shows minimal class declarations demonstrating a call to a protected base class method from a derived class override. class base { protected: // accessible to all instances of this class, its friends and its derivatives. virtual void method(){ /* do something */ } }; class derived : public base { public: // full-accessible outside of class. virtual void method(){ /* do something (or do nothing) */ base::method(); // call base class method. /* do something else (or do nothing) */ } };


What c plus plus program must be saved in a text with the extension cpp?

The .cpp extension is merely conventional; it is not required by the C++ standard. You can actually use any file extension you wish.


Write a program in cpp to print the charminar?

int main (void) { puts ("charminar"); return 0; }