小编Jan*_*sek的帖子

来自不同命名空间的模板模板参数可以成为朋友吗?

如果这个问题的标题不太有用,我道歉; 我不知道在不给出以下示例的情况下提出这个问题的简洁方法:

template <template <class> class Arg>
class C {
    typedef C<Arg> type;
    friend class Arg<type>;
  public:
    C() {
        a_.set(this);
    }
  private:
    int i_;
    Arg<type> a_;
};

template <class Type>
class Arg1 {
  public:
    void set(Type* t) {
        t_ = t;
        t_->i_ = 1;
    }
  private:
    Type* t_;
};

namespace NS {

    template <class Type>
    class Arg2 {
      public:
        void set(Type* t) {
            t_ = t;
            t_->i_ = 2;
        }
      private:
        Type* t_;
    };

}
Run Code Online (Sandbox Code Playgroud)

如你所见,Arg2是一份副本Arg1.但是,VS …

c++ templates template-templates

5
推荐指数
1
解决办法
135
查看次数

const boost :: shared_ptr <T>&作为函数参数的目的?

我正在使用一个大型且维护良好的开源C++库,并遇到了一个具有表单构造函数的类定义

class SomeClass {
    SomeClass( const boost::shared_ptr<SomeOtherClass>& );
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:const boost::shared_ptr<T>通过引用传递的重点是什么?是否真的存在与传递boost::shared_ptr<T>by值相关的不可忽略的开销量,或者传递一个boost::shared_ptr<T>我不知道的值的其他类型的危险?

c++ boost

4
推荐指数
1
解决办法
1457
查看次数

标签 统计

c++ ×2

boost ×1

template-templates ×1

templates ×1