Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > type prob

Reply
Thread Tools

type prob

 
 
Josephine Schafer
Guest
Posts: n/a
 
      11-27-2003

"Dave" <(E-Mail Removed) m> wrote in message
news:(E-Mail Removed)...
> hi
>
> another simple problem sorry. i've got a string, "Buffer", and an int, Loop.
> Somehow, this:
>
> Buffer.length<=Loop+1
>
> gives this:
>
> error C2296: '<=' : illegal, left operand has type 'unsigned int (__thiscall
> std::basic_string<char,struct std::char_traits<char>,class std::allocato
> r<char> >::*'
>
> Buffer.length should return an int, correct? loop is certainly an int. what
> am i doing wrong?


No.
Buffer.length returns std::string::size_type and not int.

Try this -
#include <string>
int main()
{
std::string Buffer("abc");
std::string::size_type loop = Buffer.length ();
}

HTH,
J.Schafer



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-27-2003
"Dave" <(E-Mail Removed) m> wrote...
> another simple problem sorry. i've got a string, "Buffer", and an int,

Loop.
> Somehow, this:
>
> Buffer.length<=Loop+1


Did you mean to say

Buffer.length()<=Loop+1

>
> gives this:
>
> error C2296: '<=' : illegal, left operand has type 'unsigned int

(__thiscall
> std::basic_string<char,struct std::char_traits<char>,class std::allocato
> r<char> >::*'
>
> Buffer.length should return an int, correct? loop is certainly an int.

what
> am i doing wrong?


You're not calling the function, you're placing its name in the
expression. That's what the compiler is telling you: "Left operand
has type '...<function declaration>...' "

Victor


 
Reply With Quote
 
 
 
 
Wouter Lievens
Guest
Posts: n/a
 
      11-27-2003
"Dave" <(E-Mail Removed) m> schreef in bericht
news:(E-Mail Removed)...
> hi
>
> another simple problem sorry. i've got a string, "Buffer", and an int,

Loop.
> Somehow, this:
>
> Buffer.length<=Loop+1
>
> gives this:
>
> error C2296: '<=' : illegal, left operand has type 'unsigned int

(__thiscall
> std::basic_string<char,struct std::char_traits<char>,class std::allocato
> r<char> >::*'
>
> Buffer.length should return an int, correct? loop is certainly an int.

what
> am i doing wrong?
>
> cheers
> dave



Though compile errors seem cryptic, they mostly speak the truth.

Left operand in this case has a function's type: that's becasue you're not
calling it!



 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-27-2003
Dave wrote:

> sorry i think i'm missing something everone else is seeing. how do i
> find the length of the string "Buffer", as an "int" data type?


You got the answer already. You must _call_ the function to get its
result. You're comparing the function itself to Loop+1, not the result
of a call to it. Buffer.length gives you the function. Buffer.length()
calls the function and gives you the result.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-27-2003
"Rolf Magnus" <(E-Mail Removed)> wrote...
> Dave wrote:
>
> > sorry i think i'm missing something everone else is seeing. how do i
> > find the length of the string "Buffer", as an "int" data type?

>
> You got the answer already. You must _call_ the function to get its
> result. You're comparing the function itself to Loop+1, not the result
> of a call to it. Buffer.length gives you the function. Buffer.length()
> calls the function and gives you the result.


Thanks, Rolf.

Now, for the inattentive ones: it's the parentheses.


 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      11-27-2003
hi

another simple problem sorry. i've got a string, "Buffer", and an int, Loop.
Somehow, this:

Buffer.length<=Loop+1

gives this:

error C2296: '<=' : illegal, left operand has type 'unsigned int (__thiscall
std::basic_string<char,struct std::char_traits<char>,class std::allocato
r<char> >::*'

Buffer.length should return an int, correct? loop is certainly an int. what
am i doing wrong?

cheers
dave


 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      11-28-2003
sorry i think i'm missing something everone else is seeing. how do i find
the length of the string "Buffer", as an "int" data type?


 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      11-28-2003
Ahahaha yes i am feeling stupid. Looks like its back to basics for me:

10 PRINT "HELLO WORLD"
20 GOTO 10

cheers
dave


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Audio prob that's more than a sound card prob LineOut Computer Support 2 04-19-2008 02:30 PM
Prob using a custom type in asp.net webservice Brian Steiner ASP .Net Web Services 2 01-21-2005 10:24 PM
Re: Type casting- a larger type to a smaller type pete C Programming 4 04-02-2004 05:19 PM
Re: Type casting- a larger type to a smaller type heyo C Programming 3 04-01-2004 06:35 PM
Printer prob and also networking prob Gareth not NLL or anybody else. Computer Support 2 01-02-2004 07:48 PM



Advertisments