Overloading Enumerated Types?

This is a discussion on Overloading Enumerated Types? within the C++ Programming forums, part of the General Programming Boards category; How do you overload an enumerated type? For example: Code: #include<iostream> using namespace std; enum example operator++(enum example& rs,int) { ...

  1. #1
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742

    Overloading Enumerated Types?

    How do you overload an enumerated type? For example:
    Code:
    #include<iostream>
    using namespace std;
    
    enum example operator++(enum example& rs,int)
    {
    	return (enum example) (rs +1);
    }
    
    int main()
    {
    	char s_print[3][10] = {"Just", "a", "string"};
    	enum example
    	{
    		just,
    		a,
    		test
    	};
    
    	for(enum example statement = just; statement <= test; statement++)
    	{
    		cout << s_print[statement];
    	}
    
    	return 0;
    }
    Can someone compile this and fix it. The only complaint from the compiler is the overloading attempt in the for loop. I need a C++ers advice.
    I compile code with:
    Visual Studio.NET beta2

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Code:
    #include<iostream>
    using namespace std;
    
    enum example
        {
            just,
            a,
            test
        };
    
    
    
    example&  operator++(example& rs,int)
    {
        return rs=(example)(rs+1);
    }
    
    int main()
    {
        char s_print[3][10] = {"Just", "a", "string"};
    
        
        for(example statement = just; statement <= test; statement++)
        {
                    
            cout << s_print[statement];
        }
    
        return 0;
    }

  3. #3
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Thank you very much. I can now see that I almost had it, but one really stupid thing that I did was define the function before I declared the enumerated type! I did a couple other things wrong too, anyway, thaks, I'll learn C++ quickly this way.
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Replies: 1
    Last Post: 02-06-2003, 02:33 PM
  4. overloading == with different data types
    By ponli in forum C++ Programming
    Replies: 2
    Last Post: 04-05-2002, 10:14 PM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM

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