我可以这样调用函数吗?

时间:2018-10-07 13:22:12

标签: c++

我有一个结构。

struct studentRec  
{
string name;
int sid;
string major;
int cohort;
};

然后,我有一个功能。

int compare_MajorName(const studentRec& s1, const studentRec& s2)

我可以这样调用函数吗?

String major = ECE;
list = new studentRec[n];
compare_MajorName(list[mid], major)

1 个答案:

答案 0 :(得分:0)

不,你不能。

您的函数参数需要studentRec s。 String无法自动转换为studentRec。没道理。

您有两种可能性:

  • 制作一个覆盖函数,该函数接受String作为第二个参数
  • 只需将结构内部的名称与您的String进行比较: list[mid].name == major例如