如何将 std::string 变量传递到函数中
我有一个 C++ 方法,它接受一个变量,方法签名如下:
DLL returnObject** getObject( const std::string folder = "" );
我尝试传入:
const std::string myString = "something";
但出现以下错误:
No matching function call to ... getObject( std::string&);
我这里有几个问题。
- 如何传递没有
&
的普通std::string
- 这看起来该值是可选的
folder = ""
是吗?如果是这样,如何传递可选参数?
I have a C++ method that takes one variable the method signature is like this:
DLL returnObject** getObject( const std::string folder = "" );
I tried passing in:
const std::string myString = "something";
but I get the following error:
No matching function call to ... getObject( std::string&);
I have a couple questions here.
- How do I pass in a normal
std::string
without the&
- This looks like the value is optional
folder = ""
is it? And if so how do you pass an optional parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个小示例按预期工作:
您可能想发布一个类似的小示例来显示您的问题。
This little example works as expected:
You might want to post a similarly small example that shows your problem.
这对我来说编译得很好,将其与您正在做的事情进行比较:
This compiled fine for me, compare it to what you're doing: