Overload operator error ?

Discussion in 'C++' started by sd2004, Jan 19, 2006.

  1. sd2004

    sd2004 Guest

    Could someone please help ?
    I am getting compiling error but do not understand why ?
    below is snipset of code:

    istream& operator>>(istream& is, test_ins& s){
    is >>s.pass>>s.put>>s.type; //line 22
    is >>s.test_one>>s.test_two>>s.test_three; /line 23
    is >>s.test_four >>s.test_five>>s.test_six; //line 24
    is>>s.force>>s.weight;
    is>>s.label>>s.start>>s.stop;
    is>>s.min>>s.max>>s.clamp;
    is>>s.time>>s.desc;
    return is;
    }

    test.cpp:22: error: syntax error before `.' token
    test.cpp:23: error: syntax error before `.' token
    test.cpp:24: error: syntax error before `.' token
    test.cpp:25: error: syntax error before `.' token
    test.cpp:26: error: syntax error before `.' token
    test.cpp:27: error: syntax error before `.' token
    test.cpp:28: error: syntax error before `.' token
    sd2004, Jan 19, 2006
    #1
    1. Advertising

  2. sd2004

    Mike Wahler Guest

    "sd2004" <> wrote in message
    news:...
    > Could someone please help ?
    > I am getting compiling error but do not understand why ?
    > below is snipset of code:
    >
    > istream& operator>>(istream& is, test_ins& s){
    > is >>s.pass>>s.put>>s.type; //line 22
    > is >>s.test_one>>s.test_two>>s.test_three; /line 23
    > is >>s.test_four >>s.test_five>>s.test_six; //line 24
    > is>>s.force>>s.weight;
    > is>>s.label>>s.start>>s.stop;
    > is>>s.min>>s.max>>s.clamp;
    > is>>s.time>>s.desc;
    > return is;
    > }
    >
    > test.cpp:22: error: syntax error before `.' token
    > test.cpp:23: error: syntax error before `.' token
    > test.cpp:24: error: syntax error before `.' token
    > test.cpp:25: error: syntax error before `.' token
    > test.cpp:26: error: syntax error before `.' token
    > test.cpp:27: error: syntax error before `.' token
    > test.cpp:28: error: syntax error before `.' token


    It appears that the compiler doesn't know what 's' is.

    Have you given the compiler all the information it
    needs? E.g. did you #include <istream> as well as
    make the definition of type 'test_ins' visible to
    this code? Is it valid to use '.' operator with
    object of type 'test_ins'? (i.e. is it a struct or
    class type?)

    -Mike
    Mike Wahler, Jan 19, 2006
    #2
    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. John Harrison
    Replies:
    1
    Views:
    1,909
  2. Piotre Ugrumov
    Replies:
    3
    Views:
    362
    Nick Hounsome
    Jan 25, 2004
  3. Gianni Mariani
    Replies:
    5
    Views:
    964
    Jerry Coffin
    Jan 18, 2005
  4. Sean
    Replies:
    7
    Views:
    395
    Kai-Uwe Bux
    Oct 6, 2005
  5. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    237
    Sherm Pendley
    Oct 11, 2004
Loading...

Share This Page