Thread: compiler error with global enum

  1. #1
    Registered User Mark S.'s Avatar
    Join Date
    May 2005
    Location
    England
    Posts
    16

    compiler error with global enum

    I am getting this error:-

    C:\C++ PROJECTS\CONSOLE\PROJECTS1\num lists menu\main.cpp(6) : fatal error C1001: INTERNAL COMPILER ERROR
    (compiler file 'msc1.cpp', line 1786)

    with this code. Why?

    Code:
    //// A menu that lists various sets of numbers///
    
    #include<iostream>
    using namespace std;
    
    enum Choice{square = 1, cube, exit};
    
    int DoMenu(void);
    
    int main(void)
    {
    	
    	int choice = 0;
    
    	while(choice != exit)
    	{
    		choice = DoMenu();		
    
    		switch(choice)
    		{
    		case square:
    			cout << "Square\n";
    			break;
    
    		case cube:
    			cout << "Cube\n";
    			break;
    
    		case exit:
    			cout << "Byee!\n";
    			break;
    		}
    
    	}
    
    	return(0);
    }
    
    int DoMenu(void)
    {
    	int choice = 0;
    
    	cout << "1. Square Numbers\n"
    		 << "2. Cube Numbers\n"
    		 << "3. Exit\n";
    
    	cin >> choice;
    
    	return(choice);
    }
    Thanks Mark S.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    There is a standard function known as exit in <cstdlib>, your <iostream> implementation may contain this library in it. Whether it contains it as <cstdlib> or <stdlib.h>, I don't know, but the former would cause a big conflict with your using directive and the latter would cause a conflict no matter what. I don't know why it wouldn't give you a clearer error if that was the problem, but it's the only problem I see. Try changing exit to something else.
    Sent from my iPadŽ

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    If you want to keep exit (read, if you MUST keep exit. I doubt you MUST), you can enclose the enum declaration in a namespace.

    Code:
    namespace foo {
        enum bar { hello, exit };
    }
    
    int main() {
        foo::bar test = foo::exit;
        if( test == foo::exit )
            std::cout << "test is of type bar. Bar is inside namespace foo. Bye";
    }
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Why not just capatolise it, or call it quit or QUIT or something like that. Ware of restricted words

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  2. Global enum?
    By Jimage in forum C Programming
    Replies: 2
    Last Post: 07-27-2007, 12:20 AM
  3. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 10:06 AM
  4. Dev C++ Compiler, Indentation?
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:13 AM
  5. defining and using a global class
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2004, 09:51 PM