I am getting into c++ from a heavy java background.
How do you have constants associated with a class?
If it was Java it would be something like
public class Example{
public static final int CONSTANT = 0;
}
public static void main (String[] args){
System.out.println(Example.CONSTANT);
}
And the result would be just 0.
In c++ I have figured so far:
class Example{
const int LEVEL_INF;
}
Is this correct?
Even by ISO 98?
is not per class, but per instance. You need to make it static:
The advantage of static const integral types is that you can initialize them inside the class, not necessarily outside:
Also, add
publicif you want public access to it.EDIT: As per @ildjarn’s suggestion, to initialize it outside the class: