CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638

    Re: Why enum works so strange? :/

    Another approach is using map of enumeration and string:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <map>
    #include <string>
    
    
    enum resolution {low,medium,hight};
    std::map<resolution,std::string > resMap;
    
    
         //class
        class display{
        int width,height;
        resolution res;
        public:
        void set(int w,int h){width=w; height=h;}
        void get(int &w,int &h){w=width; h=height;}
        void setR(resolution r){res=r;}
        std::string getR(){ return resMap[res];}
             
        };
    
    int main(int argc, char *argv[])
    {
       
       resMap[low]= "low"; 
       resMap[medium]= "medium";
       resMap[hight]= "high";
    
        display dm[3];
        int i,w,h;
        
        dm[0].set(640,480);
        dm[1].set(800,600);
        dm[2].set(1600,1200);
        
        dm[0].setR(low);
        dm[1].setR(medium);
        dm[2].setR(hight);
        
        std::cout<<"We have:"<<std::endl;
        
        for(int i=0;i<3;i++){
        dm[i].get(w,h);
        std::cout<<dm[i].getR()<<" "<<w<<"x"<<h<<std::endl;
    } 
          
        system("PAUSE");
        return 0;
    }
    Last edited by Guysl; September 19th, 2005 at 12:05 PM.
    **** **** **** **** **/**

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured