type prob

J

Josephine Schafer

Dave said:
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
 
V

Victor Bazarov

Dave said:
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
 
W

Wouter Lievens

Dave said:
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!
 
R

Rolf Magnus

Dave said:
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.
 
V

Victor Bazarov

Rolf Magnus said:
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.
 
D

Dave

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
 
D

Dave

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?
 
D

Dave

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

10 PRINT "HELLO WORLD"
20 GOTO 10

cheers
dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top