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 |
Which of the following is evaluated first: a) && b) || c) !
What is different in C++, compare with unix?
Can you please explain the difference between static and dynamic binding of functions?
What is std namespace in c++?
Difference between pass by value and pass by reference?
What is an inclusion guard?
can any one help to find a specific string between html tags which is changed to a sting.. weather.html looks (for location) is <location>somewhere</location> #include <iostream> #include <fstream> #include <string> using namespace std; string find_field(string myPage,string); int main (void) { string page, line, location, temperature; ifstream inputFile("weather.xml"); while(getline(inputFile, line)) { page.append(line); line.erase(); } // Now page is a string that contains the whole xml page // Here you need to write something that finds and // extracts location and temperature from the XML // data in the string page and stores them in // the strings location and temperature respectively location=find_field(page,"location"); temperature=find_field(page,"temp_c"); cout << "Location: "<<location << endl; cout << "Temperature: " << temperature << endl; system("pause"); } string find_field(string myPage,string find_string){ int temp=myPage.find(find_string); if(temp!=string::npos) { cout << "Match found at " << temp << endl; } return "found?"; } ///
write a program that a 5 digit number and calculates 2 power that number and prints it.
2 Answers Vimukti Technologies,
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
How can you say that a template is better than a base class?
Write a program to calculate the BMI of a person using the formula BMI = weight/height2.