When copy constructor can be used?
Answers were Sorted based on User's Feedback
Answer / jack
while compiler encounters following situation it uses the CC
1.when assigning one object to another object of same class
type
2.When an object is passed to the called function.....
3.when a function returns the object type and assigns it to
the another object..........
| Is This Answer Correct ? | 18 Yes | 4 No |
Answer / sachin magdum
1. "assigning" - don't use this word, it should be
initializing an object using another object of same type
2. When the object is passed to function - "by value"
3. when a function returns the object type - "by value"
here doesn't matter if you are assigning that returned
value to to another object or not.
| Is This Answer Correct ? | 9 Yes | 4 No |
Answer / vikas sood
hi fellows..try this code
class A {
public:
A() { }
A(const A& rhs)
{
cout<<"inside copy constructor..";
}
};
int main()
{
std::vector<A> aVec(10);
}
The answer to this is another reason a copy constructor
will be called.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / priya
Whenever u want to copy the members of one object to another
object of the same class in a C++ program.
| Is This Answer Correct ? | 3 Yes | 3 No |
Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.
what kind of projects are suitable for c and c++
Explain how would you handle a situation where you cannot call the destructor of a local explicitly?
When the design recommends static functions?
Does c++ have finally?
Is c++ harder than java?
When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?
Explain the benefits of proper inheritance.
Explain static and dynamic memory allocation with an example each.
What is the syntax for a for loop?
How do you invoke a base member function from a derived class in which you’ve overridden that function?
Can a program run without main in c++?