Solved

error C2110: cannot add two pointers

Posted on 2006-11-30
6
952 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to match SAS datasets by multiple key variables and then rename and create new variables? 2 89
NotAlone Challenge 20 84
mapBully challenge 6 136
wordcount challenge 11 123
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

832 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