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)にあります:
friend std::istream& operator>> (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
これで何が悪いのですか?