2012-07-25 92 views
0
scoped_refptr<any_class> a_scoped_refptr; 
const scoped_refptr<any_class> something = a_scoped_refptr; // Compile error. 

如果它的常量比我们无法修改ref_counter,但我想暗示指针指向的内容不应该改变,我该怎么办?是否有意义定义const scope_refptr()?

回答

1

两件事情:

首先,你没有提到的编译器错误,但我猜这是一个简单的语法错误,因为你没有为scoped_refptr指定变量名。其次,如果你想要一个指向一个const对象的指针,指定它作为指针类型。所以请尝试:

+0

谢谢,是scoped_refptr myPointer = a_scoped_refptr;与scoped_refptr myPointer = a_scoped_refptr;有什么不同? – 2012-07-25 20:22:19

+0

不;一样的。 'const mytype'只是一个C++方便的语法,用于更“适当”的'mytype const'。 – tenfour 2012-07-25 20:31:13

相关问题