Here's the statement. I believe this is using a cast operator, but what's the deal with the post increment?
(*C)(x_i,gi_tn,f)++;
Declaration and definition of C
:
std::auto_ptr<conditional_density> C(new conditional_density());
Declaration of the conditional_density
class:
class conditional_density: public datmoConditionalDensity{
public:
static const double l_min, l_max, delta;
static double x_scale[X_COUNT]; // input log luminance scale
double *g_scale; // contrast scale
double *f_scale; // frequency scale
const double g_max;
double total;
int x_count, g_count, f_count; // Number of elements
double *C; // Conditional probability function
conditional_density( const float pix_per_deg = 30.f ) :
g_max( 0.7f ){
//Irrelevant to the question
}
double& operator()( int x, int g, int f )
{
assert( (x + g*x_count + f*x_count*g_count >= 0) && (x + g*x_count + f*x_count*g_count < x_count*g_count*f_count) );
return C[x + g*x_count + f*x_count*g_count];
}
};
The parent class, datmoConditionalDensity
, only has a virtual destructor.
It would have been easy to answer this by debugging the code, but this code won't build under Windows (needs a bunch of external libraries).
(*C)(x_i,gi_tn,f)++;
Let's break it down:
(*C)
This dereferences the pointer. C is a smart pointer, and thus can be dereferenced to get the actual element being pointed to. The result is a conditional_density
object.
(*C)(x_i,gi_tn,f)
This calls the the overloaded ()
operator in the conditional_density
class. It can be strange to see it the first time, but it is an operator just like everything else. Bottom line is that it calls this code:
double& operator()( int x, int g, int f )
{
assert( (x + g*x_count + f*x_count*g_count >= 0) && (x + g*x_count + f*x_count*g_count < x_count*g_count*f_count) );
return C[x + g*x_count + f*x_count*g_count];
}
which returns a reference to a double. Finally:
(*C)(x_i,gi_tn,f)++
Because the overloaded ()
operator returns a reference to a double, I can use ++
on it which increments the double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With