上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页
摘要: In C++, compiler creates a default constructor if we don’t define our own constructor (See this). Compiler created default constructor has empty body, i.e., it doesn’t assign default values to data members (In java, default constructors assign default values). Compiler also creates a copy constru... 阅读全文
posted @ 2013-11-26 19:37 虔诚的学习者 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Predict the output of following program?1 #include 2 using namespace std;3 4 int main() 5 {6 7 cout << int() << endl;8 return 0;9 } A constructor without any arguments or with default values for every argument, is treated as default constructor. It will be called by the compiler when in 阅读全文
posted @ 2013-11-26 19:09 虔诚的学习者 阅读(376) 评论(0) 推荐(0) 编辑
摘要: Copy elision (or Copy omission) is a compiler optimization technique that avoids unnecessary copying of objects. Now a days, almost every compiler uses it. Let us understand it with the help of an example. 1 #include 2 using namespace std; 3 4 class B 5 { 6 public: 7 B(const char* st... 阅读全文
posted @ 2013-11-26 11:14 虔诚的学习者 阅读(361) 评论(0) 推荐(0) 编辑
摘要: Predict the output of the below code snippet. 1 #include 2 using namespace std; 3 4 int i; 5 6 class A 7 { 8 public: 9 ~A()10 {11 i=10;12 }13 };14 15 int foo()16 {17 i=3;18 A ob;19 return i;20 }21 22 int main()23 {24 cout 2 using namespace std; 3 4 int i; ... 阅读全文
posted @ 2013-11-26 11:06 虔诚的学习者 阅读(222) 评论(0) 推荐(0) 编辑
摘要: Predict the output of following programs. 1 #include 2 using namespace std; 3 4 class Test 5 { 6 private: 7 ~Test() 8 { 9 }10 };11 int main()12 {13 } The above program compiles and runs fine. It is not compiler error to create private destructors. What do you say about below program... 阅读全文
posted @ 2013-11-26 10:48 虔诚的学习者 阅读(410) 评论(0) 推荐(0) 编辑
摘要: A constructor without any arguments or with default value for every argument, is said to be default constructor. What is the significance of default constructor? Will the code be generated for every default constructor? Will there be any code inserted by compiler to the user implemented default... 阅读全文
posted @ 2013-11-26 10:42 虔诚的学习者 阅读(389) 评论(0) 推荐(0) 编辑
摘要: Initializer List is used to initialize data members of a class. The list of members to be initialized is indicated with constructor as a comma separated list followed by a colon. Following is an example that uses initializer list to initialize x and y of Point class. 1 #include 2 using namespace ... 阅读全文
posted @ 2013-11-26 10:37 虔诚的学习者 阅读(459) 评论(0) 推荐(0) 编辑
摘要: In C++, class variables are initialized in the same order as they appear in the class declaration. Consider the below code. 1 #include 2 3 using namespace std; 4 5 class Test 6 { 7 private: 8 int y; 9 int x; 10 public:11 Test() : x(10), y(x + 10) 12 {13 }14 void ... 阅读全文
posted @ 2013-11-26 10:24 虔诚的学习者 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Reference:http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 转载请注明:http://www.cnblogs.com/iloveyouforever/ 2013-11-26 10:16:00 阅读全文
posted @ 2013-11-26 10:16 虔诚的学习者 阅读(223) 评论(0) 推荐(0) 编辑
摘要: In C++, compiler by default creates default constructor for every class. But, if we define our own constructor, compiler doesn’t create the default constructor. For example, program 1 compiles without any error, but compilation of program 2 fails with error “no matching function for call to `my... 阅读全文
posted @ 2013-11-26 10:11 虔诚的学习者 阅读(184) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 下一页