Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213096
  • 博文数量: 35
  • 博客积分: 1480
  • 博客等级: 上尉
  • 技术积分: 390
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-14 14:27
文章分类

全部博文(35)

文章存档

2008年(35)

我的朋友

分类: C/C++

2008-03-20 09:38:44

1.  Node* rear,front;
这句rear和front的性质不同,一个是指针,一个不是;
2.char *s;
  cin>>s;
这里因为没有给 s分配内存,是不能输入字符串给s的.
3.=,[ ],(),->及所有的类型转换运算符只能作为成员函数重载
所有二元运算符一般都可以采用友员和成员函数重载.一元函数如果用友元,有一个参数,用成员,不用参数.
4.如果定义了char* p;一般不好获取p的长度.

要想得到一个外部char*的长度是很困难的,方法就是使用strlen(char*),但这种方法只能得到以'\0'结束的字符串的长度,而不能得到你实际分配给这个char*的内存的长度,并且,如果char*中存放的是自定义数据(也就是0可能是合法数据)的时候,这个方法就不能用了,最好增加一个参数来表示你传递的char*的可用内存长度。

5.写函数时,YY test(AA a,BB b) { }后面不要加; YY test(AA a,BB b);{}---YY test(AA a,BB b) { }

6.写类的成员函数时,稍微长点的程序最好都在类外实现,但是一定要加类头和模板头

7.在vs2005中

#include  

#include "stdafx.h"

using namespace std;

的错误如下:

#include "stdafx.h"   //The file is a default precompile header of a project, so any "#include" written ahead of it will be ignored.

#include    //Now, let's try to put it afterward.

using namespace std;   //Well, if only the variable 'cout' is used, writing 'using std::cout' makes the same.

8:关于函数返回指针和函数返回引用
int &a; //声明变量的时候&才表示引用
return &a;//这里&是取地址,就是一个指针,函数声明为返回指针;

可以比较下面的三个函数声明:
int *fun(){return &a;}//正确
int &fun(){return &a;}//错误
int &fun(){return a;}//正确
 
 
9:  
friend &ostream operator << (ostream& out,A& T)
{
       T.Output(out);
       return out;
       }
错误原因:
friend ostream& operator << (ostream& out,A& T)
{
       T.Output(out);
       return out;
       }
 
 
10:
写对象的拷贝函数时,忘记了初始化,拷贝函数的地位等同与构造函数,拷贝函数内部,是没有构造函数执行之前.
阅读(1164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~