Reputation: 189
I have a problem with the class in C++; it's written like this.
in second source,
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";
}
in header;
class idealtype
{public:
void compare(idealtype);
....
private:
int height;
}
in main source; ....
idealtype A(a,b,c) // c is "height"
....
idealtype B(a,b,c) // c is "height"
B.compare(A)
I think it's all done well, but Visual keeps showing me,
(in second source, on every if() state) error : expression must have class type
So, what's the KEY of this problem?
Plz help me, guys :)
Upvotes: 0
Views: 342
Reputation: 1
So, what's the KEY of this problem?
In your code you say
if (height.size() > T1.height.size())
class idealtype {
// ...
private:
int height; // <<<<<<<<<<<<
};
since height
is declared as int
it doesn't have any class like methods. That's why the compiler complains.
Upvotes: 2