本文介绍了将字符指针作为对VC ++中函数的引用进行传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,专家
在我的VC ++项目中,我正在调用方法
Hi Experts,
In my VC++ project I am calling the method
SaveErrorMsg(*"End-of-File");
通过传递字符指针.
但是我遇到了以下错误.
by passing a character pointer.
But I am getting the following error.
"cannot convert parameter 1 from 'char *' to 'char &'"
有人可以帮我吗?
我正在使用Visual Studio2008.
Can any one help me over this?
I am using Visual studio 2008.
SaveErrorMsg(*"End-of-File");// function call
void SaveErrorMsg(char &msg)
{
// Do Something
}
Thanks in advance.
推荐答案
void SaveErrorMsg(char &msg)
{
// Do Something
}
它可能看起来应该像这样:
It should probably look like this:
void SaveErrorMsg(const char* msg)
{
// Do Something
}
然后,您可以这样称呼它:
You would then call it like this:
SaveErrorMsg("End-of-File");// function call
这可能会更好:
This would probably be even better:
void SaveErrorMsg(const CString& msg)
{
// Do Something
}
// Or this
void SaveErrorMsg(const std::string& msg)
{
// Do Something
}
void SaveErrorMsg(const std::wstring& msg)
{
// Do Something
}
最好的问候
Espen Harlinn
Best regards
Espen Harlinn
这篇关于将字符指针作为对VC ++中函数的引用进行传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!