While I use switch case in parameterized constructor I get an warning..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhavalshahs
    New Member
    • Nov 2013
    • 1

    While I use switch case in parameterized constructor I get an warning..

    while i compile my code i got an warning that,
    "FUNCTIONS CONTAINS SWITCH ARE NOT EXPAND INLINE."

    Basically I am writing switch case in the parameterized constructor at that time i get this warning.

    Because of this error sometimes I can run the code and sometimes not.

    I want to know can i write switch case in parameterized constructor?If yes,then how?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Well I tried this

    Code:
    class Example
    {
    public:
      Example(int a) :
       data(a)
      {
        switch(a)
        {
        case 0:
          cout << "Special Case 0" << endl;
          break;
          
        case 1:
          cout << "Special Case 1" << endl;
          break;
          
        default:
          cout << "Default Case " << a << endl;
          break;
        }
      }
      
      ~Example()
      {
        cout << "Destroy " << data << endl;
      }
      
    private:
      int data;
    };
    Which compiled and ran without warning or error so you probably need to be more specific about what you are doing and what platform you are doing it on.

    Comment

    Working...