如何解决在属性上调用方法
我有一个具有名为title的属性的类,该类实现为嵌套类,如何在其上调用std :: strings的方法? (我正在尝试进行隐藏封装。)
#include <iostream>
class test {
public:
class {
private :
std::string value;
public:
operator const std::string & () {
return value;
}
void operator =(const std::string & source) { value = source;}
} title;
};
int main() {
test t;
t.title = "title"; // this works.
t.title.find("t"); // error here.
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。