摘要: 1 /* 为什么 赋值操作 没有被执行。*/ 2 #include 3 4 class NoName 5 { 6 public: 7 NoName(){std::cout << "good defualt" << std::endl;} 8 NoName(const NoName& obj){std::cout << "good copy" << std::endl;} 9 NoName(int i):ivar(i){std::cout << "good no_default& 阅读全文
posted @ 2013-06-23 17:41 joythink89 阅读(210) 评论(0) 推荐(0) 编辑
摘要: #include<string>class NoDefault{public: explicit NoDefault(int iv, int iiv):ivar(iv),iivar(iiv){} //加了explicit不支持隐式转换private: int ivar; int iivar;};class C{public: C();private: NoDefault no; int cc;};C::C():no(5,7),cc(0){}; //构造函数啊,或者 拷贝函数(同类型初始化)int main(){// NoDefault a = 4... 阅读全文
posted @ 2013-06-20 23:00 joythink89 阅读(131) 评论(0) 推荐(0) 编辑
摘要: #include<string>#include<fstream>std::ifstream file("text1");class NoName{public: NoName(const std::string &str):con_str(str),ref_fstream(file),ivar(0),pdvar(NULL){}private: const std::string con_str; int ivar; double* pdvar; std::ifstream &ref_fstream; // 没有拷贝函数,必须用引用} 阅读全文
posted @ 2013-06-20 16:17 joythink89 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1 #include<iostream> 2 #include<string> 3 4 class Screen 5 { 6 public: 7 typedef std::string::size_type index; 8 Screen(const std::string &con, index hx, index wx); 9 char get() const10 { return contents[cursor];}11 inline char get(index hx, index wx) const;12 inline in... 阅读全文
posted @ 2013-06-19 22:01 joythink89 阅读(185) 评论(0) 推荐(0) 编辑
摘要: http://baike.baidu.com/view/8331909.htm#1http://www.vckbase.com/index.php/wv/23.html构造函数初始化成员列表(constructor initializer list)如果CMember是另一个类的成员,你怎样初始化它呢?答案是你必须使用成员初始化列表。01.classCMyClass {02.CMember m_member;03.public:04.CMyClass();05.};06.// 必须使用初始化列表来初始化成员 m_member07.CMyClass::CMyClass() : m_member( 阅读全文
posted @ 2013-06-06 11:25 joythink89 阅读(378) 评论(0) 推荐(0) 编辑
摘要: 1 #include <cstdlib> 2 #include <iostream> 3 #include <ctime> 4 5 using namespace std; 6 7 int main( int argc, char *argv[]); 8 void timestamp( void); 9 10 int main( int argc, char *argv[])11 // argv : a pointer ( point to an array ( array stores pointers))12 {13 int i;14 bool VERB 阅读全文
posted @ 2013-06-03 20:26 joythink89 阅读(193) 评论(0) 推荐(0) 编辑
摘要: //单个源文件#include<iostream>using namespace std;bool strToInt(const char* str, int &num);int main(){ char arr[100]; cin >> arr; int numk = 0; if( strToInt(arr,numk) ) cout << numk << endl; else cout << "string to int fails" << endl; return 0;}bool strTo 阅读全文
posted @ 2013-05-30 20:11 joythink89 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 using namespace std; 3 4 int main() 5 { 6 char var = '5'; 7 char *p_var; 8 p_var = &var; 9 char *p = "shi";//字符串常量就是字符数组,后面也会自动加'\0'10 char arr[]= "lianxi";//字符数组11 return 0;12 } 阅读全文
posted @ 2013-05-30 13:35 joythink89 阅读(136) 评论(0) 推荐(0) 编辑