今天一同事闲时看了一些C++代码,于是问我 new 一个类型时后面加括号和不加括号有什么区别?如下:A* test1 = new AA* test2 = new A( ) 我竟一时答不上来。 后来查阅了一些资料,整理出一些结论,正确与否,还需认证。对于自定义的类型,两种写法是一致的。而对于内建类型,区别在于调用的构造函数不一样,例如:int* a = new int ; // a 的值不确定 int* b = new int(); // b的值被初始化为0 对于此种情况,后者比前者多了一个 memset 。 在CSDN的论坛上,也有关于这个问题的争议,不够貌似还没有最后的结论。本文转自http Read More
posted @ 2013-07-18 22:57 迷路君的博客 Views(114) Comments(0) Diggs(0) Edit
今天在csdn看到有人出了一道考数组长度的问题,感觉挺不错的,稍稍归纳一下,记录在案。chartest[]={0x01,0x02,0x03}; int a =strlen(test);intb=sizeof(test); 则 a值为不确定值,因为 strlen 判断字符串结束的标志是指针走到值为 '\000' 的地址处,'\000' 在十六进制里的表示就是 0x00。 b 值为 3,sizeof是返回变量所占内存数。 若chartest[]={0x01,0x00,0x03}; 则 a = 1 因为 0x00 为字符串结束符。b依然为3。 若chartest[20 Read More
posted @ 2013-07-18 22:53 迷路君的博客 Views(215) Comments(0) Diggs(0) Edit
一、Light在D3DLIGHT9能设置的光照类型有以下三种,分别是方向光、点光和聚光.D3DLIGHT_DIRECTIONALCreates a directional light, a light that comes from everywhere at once, but shines only in one direction.D3DLIGHT_POINTCreates a point light, a light that emanates equally in all directions from one exact point.D3DLIGHT_SPOTCreates a.. Read More
posted @ 2013-07-16 21:10 迷路君的博客 Views(471) Comments(0) Diggs(0) Edit
在渲染多边形网格对象到场景中的时候,离观察者越远的对象应该越模糊,同时离观察者越近的物体应该越清楚,这就是深度排序(depth sorting)。深度排序有两种常用的方法。第一种方法称为画家算法(painter's algorithm)。这种方法将对象划分成不同的多边形,由后往前对这些多边形进行排序,再按照排好的顺序绘制出这些多边形。采用这种方法绘制多边形,能够确保前面的多边形总是在其后多边形之前进行绘制。深度排序的第二种方法称为z缓冲方法(z- buffer),它是图形硬件设备使用最多的方法。这种方法依赖于像素,每个像素都有一个z值(z值是像素距离观察者的距离)。当每个像素被写入时, Read More
posted @ 2013-07-13 10:42 迷路君的博客 Views(598) Comments(0) Diggs(0) Edit
思路很清晰很简单的一道题,大数相加,用字符串来处理结果转化成代码时频频出错,索引值 + 1 ,-1 错误尤为突出。又一次被ACM给虐了。撸代码能力弱爆了。http://acm.cs.ecnu.edu.cn/problem.php?problemid=1001不过总算让我给AC#includeusing namespace std;int main(){ void Sum(char A[],char B[],char C[]); char A[550],B[550],C[550]; while(cin >>A && cin >> B) { Sum(A,B, Read More
posted @ 2013-07-12 16:40 迷路君的博客 Views(229) Comments(0) Diggs(0) Edit
#include<iostream>int main(){ using namespace std; double x,n,y; y = 1; double xn(double x,double n,double y); cout<<"请输入 x 和 n : "; cin >> x >> n; cout << endl << "x 的 n 次幂为 :" << xn(x,n,y);} double xn (double x,double n,double y){ y *= Read More
posted @ 2013-04-05 21:22 迷路君的博客 Views(251) Comments(0) Diggs(0) Edit
#include<iostream>template < class T > T larger(T a,T b); // 不能放在main函数里面main(){ using std::cout; int a = 1; int b = 100; cout << larger( a ,b );}template < class T > T larger(T a,T b){ return a > b ? a : b;} Read More
posted @ 2013-04-05 14:00 迷路君的博客 Views(181) Comments(0) Diggs(0) Edit
原本对于二维数组a[3][4]中的a[0]究竟指什么不确定,用了一段代码检验下#include<iostream>main(){ using std::cout; using std::endl; int a[3][4]; cout <<endl << "sizeof a == "<<sizeof a <<endl <<"i == "<<sizeof a/sizeof a[0]<<endl <<"sizeof a[0] == " Read More
posted @ 2013-04-05 13:54 迷路君的博客 Views(701) Comments(0) Diggs(0) Edit