这是声明.我相信这是使用强制转换操作符,但是后增量的处理是什么?
(*C)(x_i,gi_tn,f)++;
Run Code Online (Sandbox Code Playgroud)
声明和定义C:
std::auto_ptr<conditional_density> C(new conditional_density());
Run Code Online (Sandbox Code Playgroud)
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];
}
};
Run Code Online (Sandbox Code Playgroud)
父类datmoConditionalDensity只有一个虚拟析构函数.
通过调试代码很容易回答这个问题,但是这个代码不会在Windows下构建(需要一堆外部库).
riw*_*alk 11
(*C)(x_i,gi_tn,f)++;
Run Code Online (Sandbox Code Playgroud)
让我们分解一下:
(*C)
Run Code Online (Sandbox Code Playgroud)
这取消了指针的引用.C是一个智能指针,因此可以取消引用以获得指向的实际元素.结果是一个conditional_density对象.
(*C)(x_i,gi_tn,f)
Run Code Online (Sandbox Code Playgroud)
这会调用类中的重载()运算符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];
}
Run Code Online (Sandbox Code Playgroud)
它返回对double的引用.最后:
(*C)(x_i,gi_tn,f)++
Run Code Online (Sandbox Code Playgroud)
因为重载的()运算符返回对double的引用,所以我可以使用++它来增加double.
| 归档时间: |
|
| 查看次数: |
408 次 |
| 最近记录: |