By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,574 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,574 IT Pros & Developers. It's quick & easy.

problem regarding overloading of operator <<.

P: n/a
hi guys,

i have overloaded the << operator.as shown below.
ostream& operator<<(ostream &out, const student &a)
{
out<<a.idno;
out<< " " ;
// out<< a.name;
out<< " " ;
// out<< a.marks << endl;
return out;
}
and
ostream& operator<<(ostream &out,string1 &s1)
{
char *p;
p=s1.c_str();
out<<p;
return out;
}
here string1 is the string class i have created and student is
class student
{
public:
string1 idno;
string1 name;
int marks;
};
now i am getting this error
no match for `std::basic_ostream<char, std::char_traits<char>
>& << const string1&' operator
at the line
out<<a.idno;
the overloaded operator << for string1 class is working for other
implementation.
kindly explain me this error.
thanking you in advance.

Jul 28 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a
Hi,
ostream& operator<<(ostream &out, const student &a)
You are accepting the reference as const .
ostream& operator<<(ostream &out,string1 &s1)
this is just reference.
out<<a.idno;
As "a" is const, this call is not working with overloaded operator
accepting non-const reference to string1.

Use this =ostream& operator<<(ostream &out,const string1 &s1)
It should work.

Regards,
Amir

Jul 28 '06 #2

P: n/a
Ashwin wrote:
hi guys,

i have overloaded the << operator.as shown below.
ostream& operator<<(ostream &out, const student &a)
{
out<<a.idno;
out<< " " ;
// out<< a.name;
out<< " " ;
// out<< a.marks << endl;
return out;
}
and
ostream& operator<<(ostream &out,string1 &s1)
This should read:

stream& operator<<(ostream &out,string1 const &s1)
{
char *p;
p=s1.c_str();
out<<p;
return out;
}
Is it intentional that your string class does not allow for embedded 0
characters within strings?
here string1 is the string class i have created
Why did you create your own string class? Usually, this is a BadIdea(tm),
and I am inclined to bet that your case is in that category, too.
and student is
class student
{
public:
string1 idno;
string1 name;
int marks;
};
now i am getting this error
no match for `std::basic_ostream<char, std::char_traits<char>
>& << const string1&' operator
at the line
out<<a.idno;
the overloaded operator << for string1 class is working for other
implementation.
Which other implementation?
ps.: just use std::string.
Best

Kai-Uwe Bux
Jul 28 '06 #3

P: n/a

am******@yahoo.com wrote:
Hi,
ostream& operator<<(ostream &out, const student &a)
You are accepting the reference as const .
ostream& operator<<(ostream &out,string1 &s1)
this is just reference.
out<<a.idno;
As "a" is const, this call is not working with overloaded operator
accepting non-const reference to string1.

Use this =ostream& operator<<(ostream &out,const string1 &s1)
It should work.

Regards,
Amir
thanks Amir.
now i understand what is the problem . your explanation was very nice.
thanks a lot

Jul 28 '06 #4

P: n/a

Kai-Uwe Bux wrote:
Ashwin wrote:
hi guys,

i have overloaded the << operator.as shown below.
ostream& operator<<(ostream &out, const student &a)
{
out<<a.idno;
out<< " " ;
// out<< a.name;
out<< " " ;
// out<< a.marks << endl;
return out;
}
and
ostream& operator<<(ostream &out,string1 &s1)

This should read:

stream& operator<<(ostream &out,string1 const &s1)
{
char *p;
p=s1.c_str();
out<<p;
return out;
}

Is it intentional that your string class does not allow for embedded 0
characters within strings?
here string1 is the string class i have created

Why did you create your own string class? Usually, this is a BadIdea(tm),
and I am inclined to bet that your case is in that category, too.
and student is
class student
{
public:
string1 idno;
string1 name;
int marks;
};
now i am getting this error
no match for `std::basic_ostream<char, std::char_traits<char>
>& << const string1&' operator
at the line
out<<a.idno;
the overloaded operator << for string1 class is working for other
implementation.

Which other implementation?
ps.: just use std::string.
Best

Kai-Uwe Bux
thanks Kai-Uwe Bux for replying . i wrote my own string class from a
linked list as it was given to me as an assignment now i have to make
use of this string class. other implementation means other .cpp files
in which i have used my string class.
thanx and regards
ashwin

Jul 28 '06 #5

P: n/a

Ashwin wrote:
Kai-Uwe Bux wrote:
Ashwin wrote:
hi guys,
>
i have overloaded the << operator.as shown below.
ostream& operator<<(ostream &out, const student &a)
{
out<<a.idno;
out<< " " ;
// out<< a.name;
out<< " " ;
// out<< a.marks << endl;
return out;
}
and
ostream& operator<<(ostream &out,string1 &s1)
This should read:

stream& operator<<(ostream &out,string1 const &s1)
{
char *p;
p=s1.c_str();
out<<p;
return out;
}
Is it intentional that your string class does not allow for embedded 0
characters within strings?
here string1 is the string class i have created
Why did you create your own string class? Usually, this is a BadIdea(tm),
and I am inclined to bet that your case is in that category, too.
and student is
class student
{
public:
string1 idno;
string1 name;
int marks;
};
now i am getting this error
no match for `std::basic_ostream<char, std::char_traits<char>
>& << const string1&' operator
at the line
out<<a.idno;
the overloaded operator << for string1 class is working for other
implementation.
Which other implementation?
ps.: just use std::string.
Best

Kai-Uwe Bux

thanks Kai-Uwe Bux for replying . i wrote my own string class from a
linked list as it was given to me as an assignment now i have to make
use of this string class. other implementation means other .cpp files
in which i have used my string class.
thanx and regards
ashwin

hi guys ,

sorry to disturb you again . can any one explain me this error
/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void
std::_Construct(_T1*, const _T2&) [with _T1 = student, _T2 =
student]':
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const
_Tp&) [with _Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with
_Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = student,
_Alloc = std::allocator<student>]'
assign2.cpp:100: instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)

at assign2.cpp:100 l.push_back(s); is present

here l is list<studentl;
and s is an object of class student.

kindly explain me this error.

Jul 28 '06 #6

P: n/a
Ashwin wrote:
hi guys ,

sorry to disturb you again . can any one explain me this error
I thought you were going to fix your capitalisation?
/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void
std::_Construct(_T1*, const _T2&) [with _T1 = student, _T2 =
student]':
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const
_Tp&) [with _Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with
_Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = student,
_Alloc = std::allocator<student>]'
assign2.cpp:100: instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)
The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.
Jul 28 '06 #7

P: n/a

Ian Collins wrote:
Ashwin wrote:
hi guys ,

sorry to disturb you again . can any one explain me this error

I thought you were going to fix your capitalisation?
/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void
std::_Construct(_T1*, const _T2&) [with _T1 = student, _T2 =
student]':
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const
_Tp&) [with _Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with
_Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = student,
_Alloc = std::allocator<student>]'
assign2.cpp:100: instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)
The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.
thanks Ian Collins for replying.but when i used the standard string
class without any copy constructor for the student class it didn't give
me errors why is it giving error now.
thanks and regards
Ashwin

Jul 28 '06 #8

P: n/a
Ashwin wrote:
Ian Collins wrote:
>>Ashwin wrote:
>>>/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)

The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.
It's standard practice on Usenet not to quote signatures (anything after
--).
>
thanks Ian Collins for replying.but when i used the standard string
class without any copy constructor for the student class it didn't give
me errors why is it giving error now.
Please try and fix your capitalisation, it will make your posts easier
to read.

I'm not sure what you mean, did you use std::string in place of you
student class? If so, std::string has a copy constructor. If not,
please post some code.

--
Ian Collins.
Jul 28 '06 #9

P: n/a

Ian Collins wrote:
Ashwin wrote:
Ian Collins wrote:
>Ashwin wrote:
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)
The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.
It's standard practice on Usenet not to quote signatures (anything after
--).

thanks Ian Collins for replying.but when i used the standard string
class without any copy constructor for the student class it didn't give
me errors why is it giving error now.

Please try and fix your capitalisation, it will make your posts easier
to read.

I'm not sure what you mean, did you use std::string in place of you
student class? If so, std::string has a copy constructor. If not,
please post some code.

--
Ian Collins.
Thanks Ian Collins. I had used std:: string . Now i know where the
problem is.When i use my string class the compiler doesn't know how to
copy it to the container as it is not of standard type.Now if i write
the copy constructor for student class the compiler will know how to
load into the container, correct me if i am wrong.I hope your are happy
with the capitalisation.

Thanks and Regards
Ashwin

Jul 28 '06 #10

P: n/a
Ashwin wrote:
>
Ian Collins wrote:
>Ashwin wrote:
hi guys ,

sorry to disturb you again . can any one explain me this error

I thought you were going to fix your capitalisation?
/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void
std::_Construct(_T1*, const _T2&) [with _T1 = student, _T2 =
student]':
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const
_Tp&) [with _Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with
_Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = student,
_Alloc = std::allocator<student>]'
assign2.cpp:100: instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)
The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.

thanks Ian Collins for replying.but when i used the standard string
class without any copy constructor for the student class it didn't give
me errors why is it giving error now.
The error is somewhere in the code you did not post. Read the FAQ about how
to post. It will tell you to provide enough code for us to reproduce the
problem.

If it works with std::string instead of string1, then chances are, your
string1 class is broken and we might be seeing errors that manifest
themselves elsewhere.

Also, I doubt that you did not declare a copy constructor for student. The
compiler tells us that there is a constructor:

student::student(student&);

which qualifies as a copy constructor. However, it is not const-correct. Try

strudent( student const & );

instead.
Also, does your string1 class have a copy constructor? Is it written
const-correctly?
Best

Kai-Uwe Bux
Jul 28 '06 #11

P: n/a
Ashwin wrote:
>>
I'm not sure what you mean, did you use std::string in place of you
student class? If so, std::string has a copy constructor. If not,
please post some code.

--
Ian Collins.


Thanks Ian Collins. I had used std:: string . Now i know where the
problem is.When i use my string class the compiler doesn't know how to
copy it to the container as it is not of standard type.Now if i write
the copy constructor for student class the compiler will know how to
load into the container, correct me if i am wrong.I hope your are happy
with the capitalisation.
Yes, or more precisely, know how to copy your class.

Well done on the capitalisation, one more small detail: 'I' is always
capitalised and you should add a space after each full stop (.).

Good luck,

--
Ian Collins.
Jul 28 '06 #12

P: n/a

Kai-Uwe Bux wrote:
Ashwin wrote:

Ian Collins wrote:
Ashwin wrote:

hi guys ,

sorry to disturb you again . can any one explain me this error

I thought you were going to fix your capitalisation?

/usr/include/c++/3.2.2/bits/stl_construct.h: In function `void
std::_Construct(_T1*, const _T2&) [with _T1 = student, _T2 =
student]':
/usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from
`std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const
_Tp&) [with _Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from
`std::_List_iterator<_Tp, _Tp&, _Tp*std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with
_Tp = student, _Alloc = std::allocator<student>]'
/usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void
std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = student,
_Alloc = std::allocator<student>]'
assign2.cpp:100: instantiated from here
/usr/include/c++/3.2.2/bits/stl_construct.h:78: no matching function
for call
to `student::student(const student&)'
assign2.cpp:80: candidates are: student::student()
assign2.cpp:8: student::student(student&)

The compiler is telling you that student doesn't have a copy
constructor. Any user defined type used with a standard container must
have a public copy constructor if any other constructor is declared
because the object is copied into the container.
--
Ian Collins.
thanks Ian Collins for replying.but when i used the standard string
class without any copy constructor for the student class it didn't give
me errors why is it giving error now.

The error is somewhere in the code you did not post. Read the FAQ about how
to post. It will tell you to provide enough code for us to reproduce the
problem.

If it works with std::string instead of string1, then chances are, your
string1 class is broken and we might be seeing errors that manifest
themselves elsewhere.

Also, I doubt that you did not declare a copy constructor for student. The
compiler tells us that there is a constructor:

student::student(student&);

which qualifies as a copy constructor. However, it is not const-correct. Try

strudent( student const & );

instead.
Also, does your string1 class have a copy constructor? Is it written
const-correctly?
Best

Kai-Uwe Bux
Thanks Kai-Uwe Bux. As you said the copy constructor is strudent(
student & ) if i use const qualifier there will be errors as i
haven't used const in the copy constuctor of string1 .so i have to
change many things in my string and linked list class.I have not used
this const qualifier regulerly so these many problems. Thanks for
replying .

Thanks and Regards
Ashwin

Jul 28 '06 #13

P: n/a
Ashwin wrote:
Kai-Uwe Bux wrote:
>>
The error is somewhere in the code you did not post. Read the FAQ about how
to post. It will tell you to provide enough code for us to reproduce the
problem.

If it works with std::string instead of string1, then chances are, your
string1 class is broken and we might be seeing errors that manifest
themselves elsewhere.

Also, I doubt that you did not declare a copy constructor for student. The
compiler tells us that there is a constructor:

student::student(student&);
Whoops, I didn't spot that, not used to gcc error messages :)
>>which qualifies as a copy constructor. However, it is not const-correct. Try

strudent( student const & );

instead.
Also, does your string1 class have a copy constructor? Is it written
const-correctly?

Thanks Kai-Uwe Bux. As you said the copy constructor is strudent(
student & ) if i use const qualifier there will be errors as i
haven't used const in the copy constuctor of string1 .so i have to
change many things in my string and linked list class.I have not used
this const qualifier regulerly so these many problems. Thanks for
replying .
Copy constructors should always take a const reference as their
parameter, otherwise you will run into the exact problem you have here.
If you are not going to modify the passed value, this should be const.

--
Ian Collins.
Jul 28 '06 #14

P: n/a

Ian Collins wrote:
Ashwin wrote:
Kai-Uwe Bux wrote:
>
The error is somewhere in the code you did not post. Read the FAQ about how
to post. It will tell you to provide enough code for us to reproduce the
problem.

If it works with std::string instead of string1, then chances are, your
string1 class is broken and we might be seeing errors that manifest
themselves elsewhere.

Also, I doubt that you did not declare a copy constructor for student. The
compiler tells us that there is a constructor:

student::student(student&);
Whoops, I didn't spot that, not used to gcc error messages :)
>which qualifies as a copy constructor. However, it is not const-correct. Try

strudent( student const & );

instead.
Also, does your string1 class have a copy constructor? Is it written
const-correctly?
Thanks Kai-Uwe Bux. As you said the copy constructor is strudent(
student & ) if i use const qualifier there will be errors as i
haven't used const in the copy constuctor of string1 .so i have to
change many things in my string and linked list class.I have not used
this const qualifier regulerly so these many problems. Thanks for
replying .
Copy constructors should always take a const reference as their
parameter, otherwise you will run into the exact problem you have here.
If you are not going to modify the passed value, this should be const.

--
Ian Collins.
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::string1(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::operator[](unsigned int i)
{
char ch='\0';
if(empty())
{
cout<<"no data available"<<endl;
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::string1(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::operator[](unsigned int)' discards qualifiers
string1.h: In member function `int string1::operator=(const string1&)':
string1.h:77: passing `const string1' as `this' argument of `int
string1::len()
' discards qualifiers
string1.h:79: passing `const string1' as `this' argument of `char
string1::operator[](unsigned int)' discards qualifiers
assign2.cpp: In function `int main()':
assign2.cpp:87: no matching function for call to `student::student()'
assign2.cpp:16: candidates are: student::student(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++.

Thanks and regards
Ashwin

Jul 28 '06 #15

P: n/a
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::string1(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::operator[](unsigned int i)
{
char ch='\0';
if(empty())
{
cout<<"no data available"<<endl;
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::string1(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::operator[](unsigned int)' discards qualifiers
string1.h: In member function `int string1::operator=(const string1&)':
string1.h:77: passing `const string1' as `this' argument of `int
string1::len()
' discards qualifiers
string1::operator[](unsigned int) should be declared const, it doesn't
change the object.
string1.h:79: passing `const string1' as `this' argument of `char
string1::operator[](unsigned int)' discards qualifiers
assign2.cpp: In function `int main()':
assign2.cpp:87: no matching function for call to `student::student()'
assign2.cpp:16: candidates are: student::student(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.
Jul 28 '06 #16

P: n/a

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::string1(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::operator[](unsigned int i)
{
char ch='\0';
if(empty())
{
cout<<"no data available"<<endl;
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::string1(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::operator[](unsigned int)' discards qualifiers
string1.h: In member function `int string1::operator=(const string1&)':
string1.h:77: passing `const string1' as `this' argument of `int
string1::len()
' discards qualifiers

string1::operator[](unsigned int) should be declared const, it doesn't
change the object.
string1.h:79: passing `const string1' as `this' argument of `char
string1::operator[](unsigned int)' discards qualifiers
assign2.cpp: In function `int main()':
assign2.cpp:87: no matching function for call to `student::student()'
assign2.cpp:16: candidates are: student::student(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

Jul 28 '06 #17

P: n/a
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.
Jul 28 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.