Ray's playground

 
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 56 下一页

2011年6月13日

Item 8:Understand the different meanings of new and delete.(More Effective C++)

摘要: Though you want to create an object on the heap, use the new operator. It both allocates memory and calls a constructor for the object. If you only want to allocate memory, call operator new; no constructor will be called. If you want to customize the memory allocation that takes place when heap ob. 阅读全文

posted @ 2011-06-13 16:33 Ray Z 阅读(148) 评论(0) 推荐(0) 编辑

2011年6月11日

Item 7:Never overload &&, ||, or ,.(More Effective C++)

摘要: The purpose of operator overloading is to make programs easier to read, write, and understand, not to dazzle others with your knowledge that comma is an operator. If you don't have a good reason for overloading an operator, don't overload it. In the case of &&, ||, and ,, it's di 阅读全文

posted @ 2011-06-11 11:16 Ray Z 阅读(162) 评论(0) 推荐(0) 编辑

2011年6月10日

Item 6:Distinguish between prefix and postfix forms of increment and decrement operators.(More Effective C++)

摘要: 1#include<iostream>2usingnamespacestd;34classMyInt5{6private:7inta;8public:9MyInt(intn):a(n){};1011MyInt&operator++()12{13a+=1;14return*this;15};1617constMyIntoperator++(int)18{19MyIntold=*this;20++(*this);2122returnold;23};2425intgetValue()26{27returna;28}29};3031intmain()32{33MyInti(4);3 阅读全文

posted @ 2011-06-10 22:32 Ray Z 阅读(227) 评论(0) 推荐(0) 编辑

2011年6月9日

Item 5:Be wary of user-defined conversion functions.(More Effective C++)

摘要: Two kinds of functions allow compilers to perform such conversions: single-argument constructors and implicit type conversion operators. A single-argument constructor is a constructor that may be called with only one argument. Such a constructor may declare a single parameter or it may declare mult. 阅读全文

posted @ 2011-06-09 18:00 Ray Z 阅读(201) 评论(0) 推荐(0) 编辑

2011年6月8日

Item 4:Avoid gratuitous default constructors.(More Effective C++)

摘要: 1#include<iostream>2usingnamespacestd;34classA5{6private:7inta;8public:9A(intn):a(n){}10};1112intmain()13{14void*rawMemory=operatornew[](10*sizeof(A));1516A*a=static_cast<A*>(rawMemory);1718A*arrayOfA[10];19for(inti=0;i<10;i++)20{21new(&arrayOfA[i])A(i);22}2324for(inti=0;i<10;i 阅读全文

posted @ 2011-06-08 18:03 Ray Z 阅读(312) 评论(0) 推荐(0) 编辑

2011年6月7日

Item 3:Never treat arrays polymorphically.(More Effective C++)

摘要: 1#include<iostream>23usingnamespacestd;45classBST6{7private:8inta;910public:11BST(intn):a(n){};12intgetData(){returna;}13friendostream&operator<<(ostream&os,BST&bst);14};1516ostream&operator<<(ostream&os,BST&bst)17{18cout<<bst.getData();19returnos;20}2 阅读全文

posted @ 2011-06-07 18:02 Ray Z 阅读(397) 评论(0) 推荐(0) 编辑

2011年6月3日

Item 2:Prefer C++-style casts.(More Effective C++)

摘要: static_cast has basically the same power and meaning as the general-purpose C-style cast. It also has the same kind of restrictions. For example, you can't cast a struct into an int or a double into a pointer using static_cast any more than you can with a C-style cast. Furthermore, static_cast c 阅读全文

posted @ 2011-06-03 14:32 Ray Z 阅读(233) 评论(0) 推荐(0) 编辑

2011年6月2日

Item 1:Distinguish between pointers and references.(More Effective C++)

摘要: First, recognize that there is no such thing as a null reference. A reference must always refer to some object. As a result, if you have a variable whose purpose is to refer to another object, but it is possible that there might not be an object to refer to, you should make the variable a pointer, . 阅读全文

posted @ 2011-06-02 15:44 Ray Z 阅读(235) 评论(0) 推荐(0) 编辑

2011年4月21日

Shared Assemblies and Strongly Named Assemblies(Chapter 3 of CLR via C#)

摘要: If an assembly is to be accessed by multiple applications, the assembly must be placed into awell-known directory, and the CLR must know to look in this directory automatically when areference to the assembly is detected. This well-known location is called the global assemblycache (GAC), which can . 阅读全文

posted @ 2011-04-21 08:28 Ray Z 阅读(178) 评论(0) 推荐(0) 编辑

2011年4月20日

Building, Packaging, Deploying, and Administering Applications and Types(Chapter 2 of CLR via C#)

摘要: A response file is a text file that contains a set of compiler commandlineswitches. When you execute CSC.exe, the compiler opens response files and uses anyswitches that are specified in them as though the switches were passed to CSC.exe on thecommand line. You instruct the compiler to use a respon. 阅读全文

posted @ 2011-04-20 11:08 Ray Z 阅读(194) 评论(0) 推荐(0) 编辑

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 56 下一页

导航