错误请求'......'中的成员'......',它是非class类型'.....'
Error request for member '.......' in '......', which is of non-class type '.....'
for(i=0;i<x;i++)
{
for(j=0;j<i;j++)
{
if(bor.hasil[i]<bor.hasil[j])
{
bor.n[i].swap (bor.hasil[j]);
tmp=bor.hasil[i];
bor.hasil[i]=bor.hasil[j];
bor.hasil[j]=tmp;
}
}
}
如何修复 'bor.tes::n[i]' 中非 class 类型的成员 'swap' 的错误请求 'char'?
how to fix error request for member 'swap' in 'bor.tes::n[i]', which is of non-class type 'char'?
虽然看起来与问题中提供的代码不符,但诊断相对清楚。它抱怨试图在 bor.tes::n[i]
指定的对象上调用名为 swap()
的方法。这是不可接受的,因为 bor.tes::n[i]
的类型是 char
,它不仅没有任何名为 swap()
的方法,而且它不是 class 类型,也没有任何方法 .
你需要想出另一种方法来执行你想要的操作,比如 std::swap
:
// swap the values of x and y, provided that x is move-assignable and move-constructible
// and that y is swappable
std::swap(x, y);
或者总是有一个很好的、老式的使用临时的三向交换:
// swap the values of chars x and y:
char tmp = x;
x = y;
y = tmp;
for(i=0;i<x;i++)
{
for(j=0;j<i;j++)
{
if(bor.hasil[i]<bor.hasil[j])
{
bor.n[i].swap (bor.hasil[j]);
tmp=bor.hasil[i];
bor.hasil[i]=bor.hasil[j];
bor.hasil[j]=tmp;
}
}
}
如何修复 'bor.tes::n[i]' 中非 class 类型的成员 'swap' 的错误请求 'char'?
how to fix error request for member 'swap' in 'bor.tes::n[i]', which is of non-class type 'char'?
虽然看起来与问题中提供的代码不符,但诊断相对清楚。它抱怨试图在 bor.tes::n[i]
指定的对象上调用名为 swap()
的方法。这是不可接受的,因为 bor.tes::n[i]
的类型是 char
,它不仅没有任何名为 swap()
的方法,而且它不是 class 类型,也没有任何方法 .
你需要想出另一种方法来执行你想要的操作,比如 std::swap
:
// swap the values of x and y, provided that x is move-assignable and move-constructible
// and that y is swappable
std::swap(x, y);
或者总是有一个很好的、老式的使用临时的三向交换:
// swap the values of chars x and y:
char tmp = x;
x = y;
y = tmp;