I am a newbie to c++.
I have written a very simple program which is as below
#include<iostream>
using namespace std;
class index
{
protected:
int count;
public:
index()
{
count=0;
}
index(int c)
{
count=c;
}
void display()
{
cout<<endl<<"count="<<count;
}
void operator ++()
{
count++;
}
};
class index1:public index{
public:
void operator --()
{
count--;
}
};
int main()
{
index1 i;
i++;
cout<<endl<<"i="<<i.display();
i++;
cout<<endl<<"i="<<i.display();
i--;
cout<<endl<<"i="<<i.display();
}
But when I compile this code in G++, I get this:
In file included from /usr/include/c++/4.7/iostream:40:0,
from inheritance.cpp:1:
/usr/include/c++/4.7/ostream:480:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
/usr/include/c++/4.7/ostream:480:5: note: template argument deduction/substitution failed:
inheritance.cpp:40:30: note: cannot convert ‘i.index1::<anonymous>.index::display()’ (type ‘void’) to type ‘char’
EDIT
I changed cout<<endl<<"i="<<i.display();
to cout<<endl<<"i="; i.display();
and it solved the problem.
But now I am getting
inheritance.cpp:39:3: error: no ‘operator++(int)’ declared for postfix ‘++’ [-fpermissive]