Your question is about avoiding the bool but also implies the need for const-ness.
To avoid the bool, I'd use a boost::optional like this:
boost::optional<int> nFirst; // .. if (!nFirst) nFirst = nIdx; // and now you can use *nFirst to get its value
Then, you can enforce logical (rather than literal) const-ness like this:
const boost::optional<int> nFirst; // .. if (!nFirst) const_cast<boost::optional<int>&>(nFirst) = nIdx; // you can use *nFirst to get the value, any attempt to change it would cause a compile-time error
Using const_cast is not the safest practice, but in your particular case and as long as you only do it once it'd be OK. It simplifies both your code and your intentions: you do want a const, it's just that you want to defer it's initialisation for a bit.
Now, as songyuanyao suggested, you could directly use an int instead of a boost::optional, but the latter makes your intention explicit so I think it's better this way. In the end of day this is C++ while songyuanyao's solution is really a C-style one.
std::call_once,staticvariables or simply checking if it's already set to nIdx. Yeah, it does not stop you from assigning it to something else by accidents somewhere else in your code, but your case doesn't seem like it need that anyway.constso that any code following (in program order in the current block) would not be able to modify it. Example:Class1 x; if (expr) { Class2 obj(); x = obj.f(); } else { x.doStuff(); } const x; /* Code following sees x as const Class1 */.