小编Mic*_*ang的帖子

结构初始化参数

我有一个struct,player,如下:

struct player {
string name;
int rating;
};
Run Code Online (Sandbox Code Playgroud)

我想修改它,以便我用两个参数声明结构:

player(string, int)
Run Code Online (Sandbox Code Playgroud)

它为结构的内容分配这些值.

c++ constructor struct initialization

2
推荐指数
3
解决办法
1万
查看次数

意外的数学分部输出 - C++

我有这段测试代码(有很多其他材料;但是,它非常密集,可能与这个问题无关),这已经产生了一些莫名其妙的输出.编译时,此块:

cout << team1[m].rating << endl;
cout << team2[n].rating << endl;
cout << team1.size() << endl;
cout << team2.size() << endl;
cout << (team2[n].rating - team1[m].rating) / team2.size() << endl;
cout << (team1[m].rating - team2[n].rating) / team1.size() << endl;
Run Code Online (Sandbox Code Playgroud)

产生输出:

10 
30 
2 
2 
10 
2147483638
Run Code Online (Sandbox Code Playgroud)

'team1'和'team2'都是类型vector<player>(没有反斜杠),'player'结构如下所示:

struct player {
string name;
int rating;
player(string Name, int Rating) :
    name(Name), rating(Rating) {}
};
Run Code Online (Sandbox Code Playgroud)

c++ math types division

2
推荐指数
2
解决办法
150
查看次数

标签 统计

c++ ×2

constructor ×1

division ×1

initialization ×1

math ×1

struct ×1

types ×1