Solved

Compile Error

Posted on 2003-11-24
6
1,047 Views
Last Modified: 2007-12-19
I get following error when I compile my vc++ app.
error C2679: binary '==' : no operator defined which takes a right-hand operand of type 'const char' (or there is no acceptable conversion)

Following is the code snippet:

oNode = objDOMDoc->selectSingleNode("//MessageSize")
if (oNode!=NULL
{
MessageBox(NULL,"MessageSize Node found","Node", MB_OK);      
}            
//sprintf(sVal,"%ls",oNode->text); //convert BSTR (unsigned * string to const char)
            
MessageBox(NULL,oNode->text,"Message Size", MB_OK);
if ((oNode->text) == '1')
{
MessageBox(NULL,"0","Size", MB_OK);
iLoop = 0; //400B
}
if (oNode->text == '2') //4KB
{
MessageBox(NULL,"10","Size", MB_OK);                  
iLoop = 10;
}
if (oNode->text == '3') //40KB
{
MessageBox(NULL,"100","Size", MB_OK);                  
iLoop = 100;
}
            
0
Comment
Question by:chillu71
[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
6 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 9811059
I would say that your problem is that you're comparing the return value of the text member (probably a char * or a string) and this cannot be compared to just a char.

Try instead using "1" so that you have not char 1, but char * or string "1"

Hope this helps

Tincho



0
 

Author Comment

by:chillu71
ID: 9811137
When I change if condition to the following on all three ifs
(oNode->text == "2") I get following error

error C2666: '==' : 3 overloads have similar conversions
0
 
LVL 13

Expert Comment

by:SteH
ID: 9811143
You can compare to the first element of oNode->text as well, which is a char. In that case use a switch statement:

switch (oNode->text[0])
{
    case '1':
      MessageBox(NULL,"0","Size", MB_OK);
      iLoop = 0; //400B
      break;
    case '2':
      ....
     
}
0
Industry Leaders: 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 9

Expert Comment

by:tinchos
ID: 9811172
Ok chillu, tell me what type is oNode->text

if it is a string then you can

if ( (oNode->text) == new string("1"))
{
MessageBox(NULL,"0","Size", MB_OK);
iLoop = 0; //400B
}

if it is a char * then you can


if ( *(oNode->text) == '1' )
{
MessageBox(NULL,"0","Size", MB_OK);
iLoop = 0; //400B
}


0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 50 total points
ID: 9811234
The statement

     if ((oNode->text) == "1")

would compile but is always false, because the pointers never are equal.

Next is that oNode->text seems to be a BSTR (mostly wchar_t*) and right side would be const char*, so you have to get the same type at both sides of comparision.
Try this:

#include <comdef.h>

    ....

    if (_bstr_t(oNode->text) == _bstr_t("1"))
    {
    }

That converts both sides to class _bstr_t that has an operator== function to compare string values.

Hope that helps
Alex



0
 

Author Comment

by:chillu71
ID: 9811263
Thank You
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

759 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