answersLogoWhite

0


Best Answer

#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

10y ago
This answer is:
User Avatar

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; }

Related questions

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

what is the pure algorithm instead of cpp program?


A program without an extension name CPP will run?

Yes because a program can run without a CPP extension, especially if program extension is .exe


What is an object in Cpp?

An object is an instance of a class.


Explain a program for this pointer in cpp?

Go to the link. You will got use of "this" keywork with simple explanation and example. http://cpp.codenewbie.com/articles/cpp/1527/Keyword_this-Page_5.html


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) */ } };


Give an example of constructor and destructor in derived class?

class superclass { public: superclass() {... } // c'tor public: virtual ~superclass() {... } // d'tor }; // superclass class derived: public superclass { public: derived() : superclass() { ... } // derived c'tor public: virtual ~derived() {... } // derived d'tor }; // derived class


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.


Why the extension cpp of c?

The extension of a file containing a C program can be any extension, so long as the compiler or platform can infer the proper rules to build it. Commonly, for C programs, the extension is .c, so myfile.c would be a C program. The term cpp is not a designation for C++. It means C Program Precompiler, and it is the normal way to build one or more C programs into an executable. Over the years, cpp has evolved into being able to handle all sorts of languages. C++ is one of them. Typical extensions for C++ programs are .cc, .cpp, and .cxx.


Write a program in cpp to print the charminar?

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


A program that executes in c but not in c plus plus?

The logic to create such programs is very simple. We know that rules of programming languages. Among them the most important one is "We should not use keywords as identifiers". Based on this rule we can create many programs that execute in c but not in cpp. Suppose write a program to and two numbers. Store the two values in two variables, name the variables as class and object. then execute in c. it will produce the output, and do the same thing in cpp, it will give two errors. because we used keywords as identifiers in cpp. ex:-#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int class=10,object=26,res; res=class+object; printf("%d",res); getch(); } Or: char str3[3] = "ABC"; /* doesn't compile in C */


Will particular C program be compatible for both g c c and DEV Cpp compiler?

That is possible. Try it.