我有一个结构体,它包含对象列表下的三个变量。-名称,注册号,数量。
struct vendor
{
int reg, amt;
char add[30];
}list[10];
我已经使用引用概念创建了一个函数来查找最小金额 (amt)。
int low(vendor *p, int n)
{
int i;
min = (p->amt);
for(i =1;i<n;i++)
{
if(min > *(p->amt))
{
min = *(p->amt);
}
p++;
}
return min;
}
主要是我包含了语法:
low(list, n);
我收到一个错误:
Invalid argument of unary '*' operator.
我也尝试过使用点运算符,但没有用。 这是我的第一个在带函数的结构指针中的程序。
能否请您指出代码中的错误。
非常感谢
阿努帕姆
(更新)完整代码:
#include <iostream>
using namespace std;
struct vendor
{
int reg, amt;
char add[30];
}list[10];
int low(vendor *p, int n)
{
int i;
min = (p->amt);
for(i =1;i<n;i++)
{
if(min > (p->amt))
{
min = (p->amt);
}
p++;
}
return min;
}
int main()
{
int i;
int fa;
int n,fr;
cin >> n;
for(i =0;i<n;i++)
{
cin >>list[i].reg>>list[i].add>>list[i].amt;
// Enter reg no. , address and amount.
}
low(list, n); // Calling function
for(i = 0;i<n;i++)
{
if(fr == list[i].amt)
// This is to check for position of least amount.
// For printing the reg no. and address of least amt.
{
fa = i;
}
}
cout << fr <<"\n" << fa <<endl;
// print the reg no. and address of least amt.
}
错误:
Overloaded function with no contextual type information.
Invalid operands of types <unresolved overloaded function
Cannot resolve overloaded function
最佳答案
low()
函数中缺少 min
的声明。
int min = (p->amt);
这应该可以帮助您编译代码。
关于c++ - 结构和指针程序错误(结构,C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42175724/