Link to home
Start Free TrialLog in
Avatar of Cyber-Drugs
Cyber-DrugsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

error C2110: cannot add two pointers

Hi guys,

Can somebody help me fix this warning please?

error C2110: cannot add two pointers


Here's my code:

      CString msgTmp;
      msgTmp = "From: "+TargetPath;
      msgTmp += "\nTo: "+argv[2];

      AfxMessageBox(msgTmp);



Cheers!
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cyber-Drugs

ASKER

Cheers Axter!
Avatar of bdunz19
bdunz19

Axter's solution is correct, I just want to add some important info for you to understand why it's not working. Again, give Axter the points.

The CString class has an "operator+" which will allow you to add a char* type, or const char*, ect to the CString. So when you do an operation like:

CString tmp, tmp2;
tmp = tmp2 + "test"; // This will work because it's like saying tmp = the CString (tmp2) addition of the const char* "test"

tmp += "\nTo: "+argv[2]; // This won't work because you're trying to add a const char* plus a char*.

So when you try to add "\nTo: "+argv[2]; argv[2] is most likely in your program defined as a char*. So what you are trying to do is add a const char* with a char* and because const char* is not a class like CString it has no operator+ and doesn't know what you want to do with it. The CString::operator+ method is what allows CStrings to be able to add characters to your variable because it has the built in method to hadle the operation.

Hope that makes more sense to you when dealing with future CString operations.
Thank you very much for that breakdown Brandon, highly appreciate your time for explaining that to me. :)
FYI:
The same can be said for std::string and std::wstring, and they both have similar work around.