上一页 1 ··· 4 5 6 7 8 9 10 11 下一页
摘要: In C++, delete operator should only be used either for the pointers pointing to the memory allocated using new operator or for a NULL pointer, and free() should only be used either for the pointers pointing to the memory allocated using malloc() or for a NULL pointer. 1 #include 2 #include 3 int... 阅读全文
posted @ 2013-11-26 10:01 虔诚的学习者 阅读(246) 评论(0) 推荐(0) 编辑
摘要: Following are the differences between malloc() and operator new. (1)new calls constructors, while malloc() does not. In fact primitive data types (char, int, float.. etc) can also be initialized with new. For example, below program prints 10. 1 #include 2 3 using namespace std; 4 5 int main... 阅读全文
posted @ 2013-11-26 09:56 虔诚的学习者 阅读(168) 评论(0) 推荐(0) 编辑
摘要: Ideally delete operator should not be used for this pointer. However, if used, then following points must be considered. (1)delete operator works only for objects allocated using operator new (See http://geeksforgeeks.org/?p=8539). If the object is created using new, then we can do delete this,... 阅读全文
posted @ 2013-11-26 09:43 虔诚的学习者 阅读(380) 评论(0) 推荐(0) 编辑
摘要: In C++, this pointer is passed as a hidden argument to all non-static member function calls. The type of this depends upon function declaration. If the member function of a class X is declared const, the type of this is const X* (see code 1 below), if the member function is declared volatile, th... 阅读全文
posted @ 2013-11-26 09:37 虔诚的学习者 阅读(247) 评论(0) 推荐(0) 编辑
摘要: The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. 'this' pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available 阅读全文
posted @ 2013-11-26 09:29 虔诚的学习者 阅读(347) 评论(0) 推荐(0) 编辑
摘要: Predict the output of following C++ program: 1 #include 2 using namespace std; 3 4 class A 5 { 6 public: 7 A() { cout 2 using namespace std; 3 4 class A 5 { 6 int x; 7 public: 8 A() 9 { 10 cout 2 using namespace std; 3 4 class A 5 { 6 int x; 7 public: 8 A(... 阅读全文
posted @ 2013-11-26 09:05 虔诚的学习者 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 在C++中,类的静态成员函数有以下几点需要注意: (1)静态成员函数没有this指针 例如,下面的程序有编译错误"`this’ is unavailable for static member functions"。 1 #include 2 class Test 3 { 4 static Test * fun() 5 { 6 return this; // compiler error 7 } 8 }; 9 10 int main()11 {12 getchar();13 return 0;14 } (2)静态成... 阅读全文
posted @ 2013-11-26 08:50 虔诚的学习者 阅读(495) 评论(0) 推荐(0) 编辑
摘要: In C++ and Java, functions can not be overloaded if they differ only in the return type. For example, the following program C++ and Java programs fail in compilation. (1)C++ Program 1 #include 2 int foo() 3 { 4 return 10; 5 } 6 7 char foo() { // compiler error; new declaration of foo()... 阅读全文
posted @ 2013-11-25 22:43 虔诚的学习者 阅读(299) 评论(0) 推荐(0) 编辑
摘要: Predict the output of following C++ program. 1 #include 2 using namespace std; 3 4 class Test 5 { 6 protected: 7 int x; 8 public: 9 Test (int i):x(i) 10 { 11 }12 13 void fun() const14 {15 cout 3 using namespace std; 4 5 void fun(const int i) 6 { 7 c... 阅读全文
posted @ 2013-11-25 22:34 虔诚的学习者 阅读(290) 评论(0) 推荐(0) 编辑
摘要: In C++, following function declarations cannot be overloaded. (1)Function declarations that differ only in the return type. For example, the following program fails in compilation. 1 #include 2 int foo() 3 { 4 return 10; 5 } 6 7 char foo() 8 { 9 return 'a'; 10 }11 12 int main()13 {1... 阅读全文
posted @ 2013-11-25 22:15 虔诚的学习者 阅读(524) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 下一页