problem regarding overloading of operator <<.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Collins

    #16
    Re: problem regarding overloading of operator &lt;&lt;.

    Ashwin wrote:
    >
    Hi Ian Collins.As you and Kai-Uwe Bux said I have used the const
    qualifier now . I have not modified it's valu but if I can another
    function of the same class it is giving me errors please see the code
    below.
    string1::string 1(const string1 &s)
    {
    str=new linkedlist<char >;
    int i;
    for(i=0;i<s.len ();i++)
    {
    str->push_back(s[i]);
    }
    length=i;
    }
    i have added the const qualifier.
    >
    char string1::operat or[](unsigned int i)
    {
    char ch='\0';
    if(empty())
    {
    cout<<"no data available"<<end l;
    return ch;
    }
    else
    {
    linkedlist<char >::iterator m;
    str->begin(m);
    for(int j=0;j!=i;j++)
    {
    ++m;
    }
    return *m;
    }
    }
    i haven't changed the value of s stored as a liked list but just
    passing through the linked list using iterator and returning the
    character
    now this is the error
    >
    string1.h: In copy constructor `string1::strin g1(const string1&)':
    string1.h:53: passing `const string1' as `this' argument of `int
    string1::len()
    string1::len() should be declared const, it doesn't change the object.
    ' discards qualifiers
    string1.h:55: passing `const string1' as `this' argument of `char
    string1::operat or[](unsigned int)' discards qualifiers
    string1.h: In member function `int string1::operat or=(const string1&)':
    string1.h:77: passing `const string1' as `this' argument of `int
    string1::len()
    ' discards qualifiers
    string1::operat or[](unsigned int) should be declared const, it doesn't
    change the object.
    string1.h:79: passing `const string1' as `this' argument of `char
    string1::operat or[](unsigned int)' discards qualifiers
    assign2.cpp: In function `int main()':
    assign2.cpp:87: no matching function for call to `student::stude nt()'
    assign2.cpp:16: candidates are: student::studen t(const student&)
    >
    student doesn't have default constructor.
    so what should I do now. I was previously working on turbo c++ (not
    standardised ) in that I didnot have these kind of problems.Please
    suggest me some good books to get accustomed with this standardized
    format of c++.
    >
    What better than the one and only "The C++ Programming Language", 3rd
    edition?

    --
    Ian Collins.

    Comment

    • Ashwin

      #17
      Re: problem regarding overloading of operator &lt;&lt;.


      Ian Collins wrote:
      Ashwin wrote:

      Hi Ian Collins.As you and Kai-Uwe Bux said I have used the const
      qualifier now . I have not modified it's valu but if I can another
      function of the same class it is giving me errors please see the code
      below.
      string1::string 1(const string1 &s)
      {
      str=new linkedlist<char >;
      int i;
      for(i=0;i<s.len ();i++)
      {
      str->push_back(s[i]);
      }
      length=i;
      }
      i have added the const qualifier.

      char string1::operat or[](unsigned int i)
      {
      char ch='\0';
      if(empty())
      {
      cout<<"no data available"<<end l;
      return ch;
      }
      else
      {
      linkedlist<char >::iterator m;
      str->begin(m);
      for(int j=0;j!=i;j++)
      {
      ++m;
      }
      return *m;
      }
      }
      i haven't changed the value of s stored as a liked list but just
      passing through the linked list using iterator and returning the
      character
      now this is the error

      string1.h: In copy constructor `string1::strin g1(const string1&)':
      string1.h:53: passing `const string1' as `this' argument of `int
      string1::len()
      >
      string1::len() should be declared const, it doesn't change the object.
      >
      ' discards qualifiers
      string1.h:55: passing `const string1' as `this' argument of `char
      string1::operat or[](unsigned int)' discards qualifiers
      string1.h: In member function `int string1::operat or=(const string1&)':
      string1.h:77: passing `const string1' as `this' argument of `int
      string1::len()
      ' discards qualifiers
      >
      string1::operat or[](unsigned int) should be declared const, it doesn't
      change the object.
      >
      string1.h:79: passing `const string1' as `this' argument of `char
      string1::operat or[](unsigned int)' discards qualifiers
      assign2.cpp: In function `int main()':
      assign2.cpp:87: no matching function for call to `student::stude nt()'
      assign2.cpp:16: candidates are: student::studen t(const student&)
      student doesn't have default constructor.
      >
      so what should I do now. I was previously working on turbo c++ (not
      standardised ) in that I didnot have these kind of problems.Please
      suggest me some good books to get accustomed with this standardized
      format of c++.
      What better than the one and only "The C++ Programming Language", 3rd
      edition?
      >
      --
      Ian Collins.
      Thanks Collins . I have mada all the changes and the code is working
      now . Thanks for the help
      you all provided.
      Thanks and Regards
      Ashwin

      Comment

      • Ian Collins

        #18
        Re: problem regarding overloading of operator &lt;&lt;.

        Ashwin wrote:
        Ian Collins wrote:
        >>
        >>What better than the one and only "The C++ Programming Language", 3rd
        >>edition?
        >>
        >>--
        >>Ian Collins.
        >
        Thanks Collins . I have mada all the changes and the code is working
        now . Thanks for the help
        you all provided.
        Good. Now all you have to do is practice trimming your responses!

        --
        Ian Collins.

        Comment

        Working...