optionaler Parameter



  • kann ich in c++ eine funktion so definieren, dass ein parameter optinal ist, d.h. dass ich ihn beim auruf der funktion nicht unbedingt übergeben muss.
    z.b. so:

    void test(int x, optinal short z);
    
    void main (void)
    {
    test(3,9);
    test(2);
    }
    


  • So z.B.:

    int test(int x, short z = 4); 
    
    int test(int x, short z)
    {
      return x + z;
    }
    
    int main (void) 
    { 
      int a = test(3,9); 
      int b = test(2); 
      return a + b;
    }
    

Anmelden zum Antworten