?
Solved

C-style or function-style cast within a class method

Posted on 2003-03-04
8
Medium Priority
?
243 Views
Last Modified: 2006-11-17
This is my problem;
error C2664: 'isspace' : cannot convert parameter 1 from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.          

This is the section of code;
if(isspace(pSSNumber[i])){ // Determines it is a tab or space

Note: pSSNumber is char* class_name::pSSNumber.

This is the solution, maybe?;
if(isspace(int(pSSNumber[i]))){ // Determines it is a tab or space }

Note: the int() cast.

My question is; is there a better solution.  It turns out that I have to do a cast on many statements.  Seems to me that there should be a global solution.
0
Comment
Question by:chima
[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
8 Comments
 

Expert Comment

by:Jasonss
ID: 8068095
how about writing your own isspace() function that take char*
0
 
LVL 8

Accepted Solution

by:
Exceter earned 200 total points
ID: 8068118
char and int are synonymous terms. You will have no difficulty passing a char to isspace(). However, char* is a pointer to a char array, not a char. Your error leads me to beleive that pSSNumber is a multidimensional array. If so, this is your problem because a multi dimensional array is simply an array of pointers. Assuming that it is a two dimensional array you would check the first character in the array by saying,

if( isspace( pSSNumber[i][0] ) )

Could you post the section of code in which pSSNumber is declared?

Exceter
0
 
LVL 6

Expert Comment

by:thienpnguyen
ID: 8068123
Are you sure, pSSNumber's type is char* .

I almost think, in your program pSSNumber's type is char** .

Could you check it .
0
Independent Software Vendors: 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 8

Expert Comment

by:Exceter
ID: 8068141
>> how about writing your own isspace() function that take char*

Because char* is a pointer not a char. char* variables are not used to store characters so writing a function that checked to see if its value was equivalent to a space character would be pointless.

Exceter
0
 

Author Comment

by:chima
ID: 8068244
I believe that Exceter is right.  pSSNumber is a two demensional array. I had move this section of code from main(){} and did not think of the input statment for the array.  I will try Exceter's solution, then issue the points.  I'm new at this, therefore writing my own isspace would require more skill than what I have.

Sidebar: I did not get an email telling me that there were responses.  I wonder why?  Also, I saw that the status was/is <unlocked> what does this mean?  I read the links for "New EEs" but have not come accross its meaning.
I hope and I think that the question is still open.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8068322
>> I did not get an email telling me that there were responses.  I wonder why?  

The email notifications get behind once in a while, the notification will show up.

>> Also, I saw that the status was/is <unlocked> what does this mean?

That simply means that you have not accepted an answer to this question yet.

Exceter
0
 

Author Comment

by:chima
ID: 8068481
Exeter, you're smart and quick, thanks.
It worked.  Silly me for thinking that the problem was more difficult.  I have another question, which I will post tomorrow.  Once again thanks.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8068699
You are most welcome.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

777 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