Я хочу перегрузить присвоение значения перегруженному индексу в классе C++. Вот мой код:
#include
#include
#include
using namespace std;
class Test {
public:
void operator=(vector val) {
a = val[0];
b = val[1];
c = val[2];
}
string operator[](int index) {
if (index == 0) {
return a;
}
else if (index == 1) {
return b;
}
else {
return c;
}
}
private:
string a = "";
string b = "";
string c = "";
};
int main()
{
// What I can do
Test values;
values = { "X","Y","Z" };
cout
Подробнее здесь: https://stackoverflow.com/questions/784 ... assignment