上一页 1 ··· 3 4 5 6 7
摘要: #include #includeusing namespace std;class String{ int length; int i;private: char* m_data;//用于保护字符串 public: String(const char *str=NULL)//普通构造函数 { cout<<"调用了构造函数"<<endl; if(str==NULL) { length=0; m_data=new char(1); //指针指向这段空间 ... 阅读全文
posted @ 2013-07-17 12:33 ymonke 阅读(633) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class B {public: B(int i){coutusingnamespacestd;class A{public: A() { coutfunc(); //A::func a->func1(); //B::func B b; //A B A::func b.func(); //A::func //B析构 //A析构} 而上面的这个例子又是另外一种情况,类B公有继承类A,那么B如果创建一个对象必须得先调用父类A... 阅读全文
posted @ 2013-07-17 11:46 ymonke 阅读(281) 评论(0) 推荐(0) 编辑
摘要: 指针变量存储的是地址,所以在函数调用的时候我们能否将指针变量传递给函数?如果不知道结果,那我们可以直接问电脑,输入如下一段代码。void GetMemory(char *p){ p = (char *)malloc(100);}void Test(void){ char *str = NULL; //申明字符串指针str并让它指向空地址 GetMemory(str); strcpy(str, "hello world"); printf(str);}str为局部变量,当传递给函数时,函数不能真正使用str,用的只是str的一个备份,str的值不变。此处str的值仍然... 阅读全文
posted @ 2013-07-11 19:38 ymonke 阅读(4646) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7