java数组比较的头文件_在头文件中声明一个类,并从用户输入初始化该类的数组...

在foo.h中

#include

class apple

{

std::vector RedApple;

public:

apple(){}

apple(int num): RedApple(num){}

}

在foo.cpp中

#include "foo.h"

int main(int argc, char *argv[])

{

int num;

sscanf_s(argv[1],"%d",&num);

apple foo = num > 0 ? apple(num) : apple();

}

EDIT: 为了回应Klaus ' complaint I thought I' d添加初始化的解释,我正在评论 apple foo = num > 0 ? apple(num) : apple(); 行,所以我会在每个单词上对它进行垂直评论:

apple // This is the type of variable in the same way int is the type of int num;

foo // The name of the apple object that I am creating

= // Normally this will trigger the assignment operator (but in a declaration line the compiler will optimize it out)

num > 0 ? // The condition to a ternary operator if true the statement before the : is executed if false the one after is executed

apple(num) // If num is greater than 0 use the non-default constructor

: apple(); // If num is less than or equal to 0 use the default number cause we can't initialize arrays negatively

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值