定义const scope_refptr()是否有意义?

时间:2012-07-25 19:04:10

标签: c++ chromium

scoped_refptr<any_class> a_scoped_refptr;
const scoped_refptr<any_class> something = a_scoped_refptr; // Compile error.

如果它是const而不是我们无法修改ref_counter,但我想暗示指针指向的内容不应该改变,我该怎么办?

1 个答案:

答案 0 :(得分:1)

两件事:

首先,您没有提到编译器错误,但我猜这是一个简单的语法错误,因为您没有为scoped_refptr指定变量名。

其次,如果需要指向const对象的指针,请将其指定为指针类型。所以试试:

scoped_refptr<any_class const> myPointer = a_scoped_refptr;
相关问题