#include <iostream>
using namespace std;
struct adv_t{
int show;
int click;
int charge;
};
class CCal{
public:
int cal_sum(adv_t adv_t[], int arr_size, int adv_t::*field_ptr){
int sum = 0;
if (field_ptr != NULL){
for (int i=0; i<arr_size; i++){
sum += adv_t[i].*field_ptr;
}
}
return sum;
};
};
int main(int argc, char const *argv[])
{
adv_t advs[5] = {
{0, 0, 0},
{1, 0, 0},
{1, 1, 100},
{1, 1, 200},
{0, 0, 0}
};
CCal* cCal = new CCal();
cout << cCal->cal_sum(advs, sizeof(advs)/sizeof(adv_t), &adv_t::show) << endl;
cout << cCal->cal_sum(advs, sizeof(advs)/sizeof(adv_t), &adv_t::click) << endl;
cout << cCal->cal_sum(advs, sizeof(advs)/sizeof(adv_t), &adv_t::charge) << endl;
return 0;
}
C++ 结构体成员指针
编程语言相关文章
C++相关文章
最近热门
- DALL-E 3:OpenAI推出的先进图像生成系统
- 在TensorFlow中计算模型的FLOPS(浮点运算次数)
- 华为昇腾910B:华为自主研发的高性能人工智能处理器芯片
- Go | 强制类型转换 .(类型)
- GPU_private 模式:TensorFlow 中用于优化 GPU 计算性能的一种线程分配策略
- 推荐系统 | MMR - Maximal Marginal Relevance
- tf.norm
- LHUC(Learning Hidden Unit Contributions)
- GraphGPS:Recipe for a General, Powerful, Scalable Graph Transformer
- Wasserstein loss
最常浏览
- 016 推荐系统 | 排序学习(LTR - Learning To Rank)
- 偏微分符号
- i.i.d(又称IID)
- 利普希茨连续条件(Lipschitz continuity)
- (error) MOVED 原因和解决方案
- TextCNN详解
- 找不到com.google.protobuf.GeneratedMessageV3的类文件
- Deployment failed: repository element was not specified in the POM inside distributionManagement
- cannot access com.google.protobuf.GeneratedMessageV3 解决方案
- CLUSTERDOWN Hash slot not served 问题原因和解决办法
×