Answer Posted / sudha
A copy constructor is a special constructor in the C++
programming language used to create a new object as a copy
of an existing object.
There are 3 important places where a copy constructor is
called.
When an object is created from another object of the same
type
When an object is passed by value as a parameter to a
function
When an object is returned from a function
class B //With copy constructor
{
private:
char *name;
public:
B()
{
name = new char[20];
}
~B()
{
delete name[];
}
//Copy constructor
B(const B &b)
{
name = new char[20];
strcpy(name, b.name);
}
};
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What are functions in oop?
What is and I oop mean?
What is object-oriented programming? Webopedia definition
What is polymorphism give a real life example?
Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.
What is debug class?what is trace class? What differences are between them? With examples.
#include
What is multilevel inheritance?
2. Give the different notations for the class.\
What are the 4 pillars of oop?
What is inheritance and how many types of inheritance?
What is the significance of classes in oop?
can inline function declare in private part of class?
What are benefits of oop?
How do you define a class in oop?