type prob

Discussion in 'C++' started by Josephine Schafer, Nov 27, 2003.

  1. "Dave" <> wrote in message
    news:...
    > 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
    Josephine Schafer, Nov 27, 2003
    #1
    1. Advertising

  2. "Dave" <> 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
    Victor Bazarov, Nov 27, 2003
    #2
    1. Advertising

  3. "Dave" <> schreef in bericht
    news:...
    > 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!
    Wouter Lievens, Nov 27, 2003
    #3
  4. Josephine Schafer

    Rolf Magnus Guest

    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.
    Rolf Magnus, Nov 27, 2003
    #4
  5. "Rolf Magnus" <> 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.
    Victor Bazarov, Nov 27, 2003
    #5
  6. Josephine Schafer

    Dave Guest

    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
    Dave, Nov 27, 2003
    #6
  7. Josephine Schafer

    Dave Guest

    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?
    Dave, Nov 28, 2003
    #7
  8. Josephine Schafer

    Dave Guest

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

    10 PRINT "HELLO WORLD"
    20 GOTO 10

    cheers
    dave
    Dave, Nov 28, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. heyo
    Replies:
    3
    Views:
    884
    Dan Pop
    Apr 1, 2004
  2. pete
    Replies:
    4
    Views:
    779
    Dan Pop
    Apr 2, 2004
  3. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    879
    Yevgen Muntyan
    Feb 13, 2007
  4. kj
    Replies:
    5
    Views:
    396
  5. Brian Steiner

    Prob using a custom type in asp.net webservice

    Brian Steiner, Jan 18, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    158
    Elroyskimms
    Jan 21, 2005
Loading...

Share This Page