zoukankan      html  css  js  c++  java
  • 记录昨日程序调不通的解释

    C++规定了

    1.函数模板作友元,但函数模板的参数和类模板的参数无关 对所有实例化类都是友元
    就是这种写法
    tempalate<typename valtype>
    class A{
    template <typename T>
    friend std::ostream& operator<<( std::ostream &, const TemplateClass<T> &); }


    2.函数模板作友元,且用到了相应类模板的参数 那么它不是所有实例化类的友元,只是特定于一个实例化的类
    就是这种写法
    tempalate<typename valtype>
    class A{
    friend std::ostream& operator<<( std::ostream &, const TemplateClass<valtype> &); }


    VC6两中都支持 VS2005后都不支持了
    我想是因为两种写法的区别太纠结 使用起来太繁琐
    那么应该是VS2005编译器直接让后一种写法报错了

    算法19群朋友flib的解释,感谢之~~

    原问题是:

    加上friend std::ostream& operator<<( std::ostream &, const TemplateClass<valtype> &);这一句以后VS2008一直报lnk错误~~后来在这个friend之前加上tempalate<typename valtype>之后通过。。然后我自己的理解是vc6.0对模板的支持不是很好~群里的朋友给出了上述解释~~

  • 相关阅读:
    C#_数据访问类查询 和 属性扩展
    C#_0913 完整修改删除、实体类和数据访问类
    webform基础
    TreeView, 数据导出
    无边框窗体,tiner控件
    容器,打印设置
    多窗体,菜单工具栏
    公共控件
    winform
    数据访问类查询
  • 原文地址:https://www.cnblogs.com/ziyoudefeng/p/2413315.html
Copyright © 2011-2022 走看看