Re: problem regarding overloading of operator <<.
Ashwin wrote:
string1::len() should be declared const, it doesn't change the object.
string1::operat or[](unsigned int) should be declared const, it doesn't
change the object.
student doesn't have default constructor.
What better than the one and only "The C++ Programming Language", 3rd
edition?
--
Ian Collins.
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()
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()
' 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.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
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&)
>
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&)
>
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++.
>
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++.
>
edition?
--
Ian Collins.
Comment