gpt4 book ai didi

c++ - 错误 : expression must have class type

转载 作者:行者123 更新时间:2023-11-28 02:51:50 25 4
gpt4 key购买 nike

我对 C++ 中的类有疑问;是这样写的。

在第二个来源中,

void idealtype::compare(idealtype T1)
{
if (height.size() > T1.height.size())
cout << T1.getname() << " " << T1.getage() << "\t" << T1.getheight() << "\n";
else if (height.size() < T1.height.size())
cout << getname() << " " << getage() << "\t" << getheight() << "\n";
else if (height.size() == T1.height.size())
{
cout << T1.getname() << " " << T1.getage() << "\t" << T1.getheight() << "\n";
cout << getname() << " " << getage() << "\t" << getheight() << "\n";
}
cout << "\n";
}

在标题中;

class idealtype
{public:
void compare(idealtype);

....

private:
int height;
}

在主要来源;....

idealtype A(a,b,c) // c is "height"

....

idealtype B(a,b,c) // c is "height"
B.compare(A)

我认为这一切都做得很好,但 Visual 一直向我展示,

(在第二个来源中,在每个 if() 状态)错误:表达式必须具有类类型

那么,这个问题的关键是什么?

请帮帮我,伙计们:)

最佳答案

So, what's the KEY of this problem?

在你的代码中你说

if (height.size() > T1.height.size())

class idealtype {
// ...
private:
int height; // <<<<<<<<<<<<
};

因为 height 被声明为 int 它没有任何类似方法的类。这就是编译器提示的原因。

关于c++ - 错误 : expression must have class type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22867220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com