operator overloading, long error

This is a discussion on operator overloading, long error within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm, trying to learn operator overloading. I try to compile this and I get an error a page long... ...

  1. #1
    glorified ape
    Guest

    operator overloading, long error

    Hi, I'm, trying to learn operator overloading. I try to compile this and I get an error a page long... Anyone know what's wrong?? thanks

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Counter
    {
    public:
      Counter ();
      ~Counter ()
      {
      };
      int GetItsVal () const
      {
        return itsVal;
      }
      void SetItsVal (int x)
      {
        itsVal = x;
      }
      void Increment ()
      {
        ++itsVal;
      }
      const Counter & operator++ ();
    
    private:
      int itsVal;
    };
    
    Counter::Counter ():
    itsVal (0)
    {
    };
    
    const Counter &
    Counter::operator++ ()
    {
      ++itsVal;
      return *this;
    }
    
    int
    main (int argc, char *argv[])
    {
      Counter i;
      cout << "The value of i is " << i.GetItsVal () << endl;
      i.Increment ();
      cout << "The value of i is " << i.GetItsVal () << endl;
      ++i;
      cout << "The value of i is " << i.GetItsVal () << endl;
    
      Counter a = ++i;
      cout << "The value of a: " << a.GetItsVal () << " and i: " << i.GetItsVal;
      cout << endl;
    
      return 0;
    }

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    In the last print statement,

    i.GetItsVal;

    should be

    i.GetItsVal();

    Otherwise it compiles cleanly for me on two different compilers.
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  4. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21