Код: Выделить всё
class Foo {
int value;
public:
Foo(int v) : value(v) {}
};
// A function that does something with a Foo
void bar(Foo& f)
{
// ...whatever
}
// This gives an error in C++20 but not in C++17
// The message is something like "cannot convert from Foo to T&"
bar(Foo(3));
< /code>
Какова причина? Есть ли улов для исправления этого кода? Есть сотни < /strong> из них. < /P>
Дополнение: Код выше немного бесполезен, потому что я думал только о синтаксисе, когда я напечатал его.class DataSource; // Abstract source of data
// Can read ASCII/UTF8/Unicode from a DataSource
class TextReader {
DataSource& source;
public:
TextReader(DataSource& s) : source(s) {}
};
// Read some text
void readText(TextReader& r)
{
}
void main()
{
FileDataSource d("file.text");
readText(TextSource(d)); // Neat!
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ter-in-c20