WHEN A COPY CONSTER IS CALL ?
Answers were Sorted based on User's Feedback
Answer / preeti
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 A //With copy constructor
{
private:
char *name;
public:
A()
{
name = new char[20];
}
~A()
{
delete name[];
}
//Copy constructor
A(const A &b)
{
name = new char[20];
strcpy(name, b.name);
}
};
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / achal ubbott
Question on copy constructor is a classic one for an
interview. Since most modern day c++ compilers provide a
default copy constructor, most people don't get to try
hands over it. But in some cases it becomes mandatory to
define your own copy constructor and override the default
one.
So the places when CC is invoked are:-
1. calling a function e.g. void f(sample A);
2. creating an object from the existing object.
e.g. sample A=B; // here B is existing object.
3. When a function returns a copy of object.
e.g. sample f()
{
sample a;
return a;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vishwa
emp e;//default constr
emp e(10);//paramatrisized constr
emp e(e1);//copy constr
emp e = e1;//copy constr
| Is This Answer Correct ? | 2 Yes | 0 No |
Why do we use inheritance?
How to reverse a sentence in c program ex: ram is a good boy answer: boy good a is ram
diff between Abstract class Interfaces?
Explain polymorphism? What r the types of polymorphism? pls give examples?
how to create thread in java?
17 Answers IBM, Infosys, Wipro,
Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.
What is variable example?
How to use CMutex, CSemaphore in VC++ MFC
• What are the desirable attributes for memory managment?
#include <string.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> void select(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); select(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void select(char *items, int count) { register int a, b, c; int exchange; char t; for(a = 0; a < count-1; ++a) { exchange = 0; c = a; t = items[ a ]; for(b = a + 1; b < count; ++b) { if(items[ b ] < t) { c = b; t = items[ b ]; exchange = 1; } } if(exchange) { items[ c ] = items[ a ]; items[ a ] = t; } } } design an algorithm for Selection Sort
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku