5

I'm working in C++ and want to create a function with an optional parameter that is a QMap. The question is what do I set the default value to. I want it to be an empty map.

void function(int i, QMap< QString, QString > MyMap = ???)

what do you put for ???

R Sahu
  • 204,454
  • 14
  • 159
  • 270
user3685722
  • 91
  • 1
  • 5

2 Answers2

4

Question:

what do you put for ???

  1. You can put a default constructed object.

    void function(int i, QMap< QString, QString > MyMap = QMap<QString, QString>())
    
  2. You can put a call to a function that returns a compatible object.

    QMap< QString, QString > const& foo();
    void function(int i, QMap< QString, QString > MyMap = foo())
    
R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

You can use a pointer to QMap (QMap*) and give it the NULL value as default:

void function(int i, QMap< QString, QString > *MyMap = NULL)
{

}