0

I have a function define in header file as this:

int myfunction(VpTR*& viewporttable,  wchar* vpname=L"*Active", OpenMode f=fR);

how i can call this function but ignore second argument? I tried calling it with the following code but an error message appeared: expected an expression

myfunction(myviewporttable,, fR);

can i omit this argument but it still understands L "* Active" as the called value?

4
  • 4
    You can't. C++ doesn't have named parameters support some other languages have so you cannot omit any parameter Commented Sep 25, 2020 at 14:10
  • You can still call it with arguments: myfunction(myviewportable, L"*Active", fR) Commented Sep 25, 2020 at 14:12
  • Make a helper forwarding function int myfunction(VpTR*& viewporttable, OpenMode f) { return myfunction(viewporttable, L"*Active", f); } Commented Sep 25, 2020 at 14:13
  • Thanks everyone, my problem is solved! Commented Sep 26, 2020 at 3:16

1 Answer 1

0

The syntax doesn't allow to omit parameter values at arbitrary positions, only those at the very end of the list.

You have to overload 2 versions:

int myfunction(VpTR*& viewporttable,  OpenMode f=fR) {
    return myfunction(viewporttable,L"*Active",L"*Active",f);
}

int myfunction(VpTR*& viewporttable,  wchar* vpname=L"*Active", OpenMode f=fR);

Then you can call

myfunction(myviewporttable, fR);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.