Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
scoped_refptr<any_class> a_scoped_refptr; const scoped_refptr<any_class> something = a_scoped_refptr; // Compile error.
如果是const比我们不能修改ref_counter,但是我想暗示指针指向的内容不应该改变,我该怎么办?
两件事情:
首先,您没有提到编译器错误,但我猜这是一个简单的语法错误,因为您没有为scoped_refptr.
scoped_refptr
其次,如果您想要一个指向 const 对象的指针,请将其指定为指针类型。所以试试:
scoped_refptr<any_class const> myPointer = a_scoped_refptr;