ber*_*art 1 c++ string pointers dereference
我问这个是因为我在编译时遇到了编译错误:
*string3.find('h');
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
error: request for member 'find' in 'string3', which is of pointer type 'std::string* {aka std::basic_string<char>*}' (maybe you meant to use '->' ?)
Run Code Online (Sandbox Code Playgroud)
我认为这会有效,因为*string3是一个字符串,*操作符取消引用指针,以便我正在使用实际的字符串.一般来说,类函数在C++中是不是以这种方式工作的?
注意:我知道我可能不需要指针.这只是我教授关于此片段的作业规范之一.
使用 :
string3->find('h');
Run Code Online (Sandbox Code Playgroud)
要么
(*string3).find('h');
Run Code Online (Sandbox Code Playgroud)
.具有较高的比优先 *