试图operator>>
用于我的班级飞机,我的main()
. 它说
"no operator ">>" matches these operands Air.
operand types are: std::istream >> Aircraft *"
我的主要():
int main()
{
Aircraft* air[2];
int choice;
std::cout << "Plane '1' and Helicopter '2'" << std::endl;
std::cin >> choice;
if (choice == 1)
{
Plane p;
air[0] = new Plane;
std::cin >> air[0]; //HERE IS AN ERROR
air[0]->ShowTabl();
std::cout << air[0];
}
/*if (choice == 2)
{
//air[1] = new Helicopter;
//TODO: << and >>
}*/
system("pause");
return 0;
}
我的阅读():
std::istream& Aircraft::read(std::istream& frFile)
{
std::cout << "Name: ";
frFile >> Name;
std::cout << "Weight: ";
frFile >> weight;
return frFile;
}
运营商>>
:
它在(.h)中:
朋友 std::istream& 运算符>> (std::istream& is, Aircraft& A);
它在(.cpp)中:
std::istream& operator >> (std::istream& is, Aircraft& A)
{
return A.read(is);
}
至于以某种方式使用,像这样,它是完美的:
Plane p;
air[0] = new Plane;
std::cin >> p; // it's okay
我做错了什么?