我有一个 C++ 方法,它接受一个变量,方法签名如下:
DLL returnObject** getObject( const std::string folder = "" );
Run Code Online (Sandbox Code Playgroud)
我尝试传入:
const std::string myString = "something";
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
No matching function call to ... getObject( std::string&);
Run Code Online (Sandbox Code Playgroud)
我这里有几个问题。
std::string
没有&
folder = ""
是吗?如果是这样,如何传递可选参数?这个小例子按预期工作:
#include <stdio.h>
#include <string>
class foo {
public:
void getObject( const std::string folder = "" );
};
int main ()
{
const std::string myString = "something";
foo* pFoo = new foo;
pFoo->getObject( myString);
pFoo->getObject(); // call using default parameter
return 0;
}
void foo::getObject( const std::string folder)
{
printf( "folder is: \"%s\"\n", folder.c_str());
}
Run Code Online (Sandbox Code Playgroud)
您可能想发布一个类似的小示例来显示您的问题。
归档时间: |
|
查看次数: |
6653 次 |
最近记录: |