error: conversion from 'Counter' to non-scalar type 'CountDn' in c++

Viewed 196
#include <iostream>
using namespace std; 
class Counter
{
protected:
unsigned int count;
public:
    Counter ():count ()
  { }
    Counter (int c):count (c)
  { }
  unsigned int get_count () const
  { return count;}
  Counter operator ++ ()
  {return Counter (++count);}
  };

  class CountDn:public Counter
  {
  public:CountDn ():Counter (){ }
  CountDn (int c):Counter (c){ }
  CountDn operator -- ()
  {return CountDn (--count);}
  };

  int main ()
  {
    CountDn c1;
    CountDn c2 (100);
    cout << "\nc1=" << c1.get_count ();
    cout << "\nc2=" << c2.get_count ();
    ++c1;
    ++c1;
    ++c1;
    cout << "\nc1=" << c1.get_count ();
    --c2;
    --c2;
    cout << "\n c2=" << c2.get_count ();
    CountDn c3 = ++c2;
    cout << "\n c3=" << c3.get_count ();
    cout << endl;
    return 0;
}

I am getting given error when I use overloaded '++' operator while it works out fine when I use '--'.

Error message is

37:14: error: conversion from ‘Counter’ to non-scalar type ‘CountDn’ requested
 CountDn c3 = ++c2;

Why do I obtain this error? What does this error mean and how can I solve it?

2 Answers
Related