primer: 12.21

#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;  // 没有拷贝函数,必须用引用
};

int main()
{
//    std::ifstream file2 = file;   //编译出错,没有拷贝函数。。
    std::string str = "ddlkd";
    NoName a(str);
    return 0;
}
View Code

 

遇到细节的问题,首先是查文档类的网站,http://www.cplusplus.com而不是谷歌百度。
posted @ 2013-06-20 16:17  joythink89  阅读(120)  评论(0编辑  收藏  举报