Solved

error C2110: cannot add two pointers

Posted on 2006-11-30
6
950 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
  • 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mac OS 9 (Classic Environment) vs. MacBook Pro OS 10 8 37
iSeries DB2 Query 2 84
only14 challenge 19 64
Problem to event 3 50
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now