Solved

error C2110: cannot add two pointers

Posted on 2006-11-30
6
953 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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