声明如下。我相信这是在使用强制转换运算符,但是后增量有什么用呢?
(*C)(x_i,gi_tn,f)++;
C
的声明和定义:
std::auto_ptr<conditional_density> C(new conditional_density());
conditional_density
类的声明:
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];
}
};
父类 datmoConditionalDensity
只有一个虚析构函数。
通过调试代码很容易回答这个问题,但这段代码无法在 Windows 下构建(需要一堆外部库)。
最佳答案
(*C)(x_i,gi_tn,f)++;
让我们分解一下:
(*C)
这取消了指针的引用。 C 是一个智能指针,因此可以取消引用以获取所指向的实际元素。结果是一个 conditional_density
对象。
(*C)(x_i,gi_tn,f)
这会调用 conditional_density
类中重载的 ()
运算符。第一次看到它可能会很奇怪,但它和其他一切一样都是一个运算符。底线是它调用这段代码:
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];
}
返回对 double 值的引用。最后:
(*C)(x_i,gi_tn,f)++
因为重载的 ()
运算符返回对 double 的引用,我可以在其上使用 ++
来增加 double。
关于c++ - 这个 C++ 语法是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12484222/