By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 926 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

type prob

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Dave" <da**********************************@hotmail.co m> wrote in message
news:3f******@dnews.tpgi.com.au...
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

Jul 22 '05 #2

P: n/a
"Dave" <da**********************************@hotmail.co 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
Jul 22 '05 #3

P: n/a
"Dave" <da**********************************@hotmail.co m> schreef in bericht
news:3f******@dnews.tpgi.com.au...
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!

Jul 22 '05 #4

P: n/a
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?
Jul 22 '05 #5

P: n/a
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.

Jul 22 '05 #6

P: n/a
"Rolf Magnus" <ra******@t-online.de> 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.
Jul 22 '05 #7

P: n/a
Ahahaha yes i am feeling stupid. Looks like its back to basics for me:

10 PRINT "HELLO WORLD"
20 GOTO 10

cheers
dave
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.