Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a parameter wasn't passed in when creating an object?

Tags:

c++

c++98

I'm translating some code, and in this completely unused private language, the code states that if more than 4 parameters were passed in (as the 5th parameter is optional), then do something to the value of that parameter, like so:

if (ParamCount > 4) {
    if (ID == 0) {
        ID = 0x700;
        if (mtrx > 0) {ID = 0x11AA0FF0; }
    }
    BaseID = ID;
} else {
    BaseID = ID;
}

How would I write this out in C++98? I created a constructor which takes in those parameters, as I am trying to turn this bit of code into a class, yet when a parameter is optional you have to set it a value, like 0, or so I thought.

like image 212
Tryb Ghost Avatar asked Jan 27 '23 13:01

Tryb Ghost


1 Answers

Overload the function instead.

The version with 5 parameters uses the true part of the if.

The other version uses the false part of the if.

like image 87
Bathsheba Avatar answered Feb 08 '23 23:02

Bathsheba