Solved

error C2110: cannot add two pointers

Posted on 2006-11-30
6
954 Views
Last Modified: 2013-11-20
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!
0
Comment
Question by:Cyber-Drugs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
ID: 18048060
Try the following:
     msgTmp = CString(_T("From: ")) + TargetPath;
     msgTmp += CString(_T("\nTo: ")) + argv[2];
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 500 total points
ID: 18048074
or.....
     msgTmp = "From: ";
     msgTmp += TargetPath;
     msgTmp += "\nTo: ";
     msgTmp += argv[2];
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18048117
Cheers Axter!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:bdunz19
ID: 18048140
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.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18048202
Thank you very much for that breakdown Brandon, highly appreciate your time for explaining that to me. :)
0
 
LVL 30

Expert Comment

by:Axter
ID: 18048223
FYI:
The same can be said for std::string and std::wstring, and they both have similar work around.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question