我想使用重載的運算符,但不知道如何使用/調用它在我的主要CPP。該代碼在另一個文件中,如下所示:使用重載的運算符[]
string postH::operator[](int add){
if(add > 100)
{return "\nsome text\n";}
else {return "\nsome other text\n";}
}
我想使用重載的運算符,但不知道如何使用/調用它在我的主要CPP。該代碼在另一個文件中,如下所示:使用重載的運算符[]
string postH::operator[](int add){
if(add > 100)
{return "\nsome text\n";}
else {return "\nsome other text\n";}
}
您可以像使用普通數組索引一樣使用它。
postH foo;
std::cout << foo[150];
THX它的工作: )使它像這樣,只是不知道它需要在前面cout :) – JohnnnnnY
@JánosBalázs它*不需要''cout'在前面。 – juanchopanza
這使我想知道爲什麼你沒有超載它在所有... – PlasmaHH