Click here to Skip to main content
15,070,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

In my VC++ project I am calling the method
C++
SaveErrorMsg(*"End-of-File");
by passing a character pointer.
But I am getting the following error.
"cannot convert parameter 1 from 'char *' to 'char &'"
Can any one help me over this?
I am using Visual studio 2008.
C++
SaveErrorMsg(*"End-of-File");// function call

void SaveErrorMsg(char &msg)
	{		
		// Do Something
	}


Thanks in advance.
Posted
Updated 3-Mar-12 6:32am
v2
Comments
André Kraak 3-Mar-12 12:32pm
   
Edited question:
Added pre tags
"Treat my content as plain text..." option disabled.

1 solution

It's unlikely the SaveErrorMsg function is declared correctly as the following takes a reference to a single char as it's argument:
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
}


Best regards
Espen Harlinn
   
Comments
   
Right, a 5.
Usually, passing a pointer by reference makes no sense.
I think it's always a good advice to use std:string instead of stupid null-terminated strings.
--SA
Espen Harlinn 4-Mar-12 4:26am
   
Thank you Sergey :)
Arun India 5-Mar-12 1:43am
   
Thanks SAKryukov for your valuable comments..
Arun India 5-Mar-12 1:42am
   
Thank you so much Espen Harlinn. This makes sense.I have updated the code based on your input and now the issue is got resolved. My 5 for you..
Espen Harlinn 5-Mar-12 3:49am
   
Brilliant, glad it worked out for you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900