Portál AbcLinuxu, 30. listopadu 2025 18:56
Řešení dotazu:
class MyType { ... }
MyType& return_ref()
{
return *(new MyType());
}
MyType& ref = return_ref();
...
delete &ref;
ProcResourceValues& ResourceCalculator::emptyProcResourceValues() {
return *(new ProcResourceValues(0,0,0));
}
error: invalid initialization of non-const reference of type 'ProcResourceValues&' from a temporary of type 'ProcResourceValues*'
class ProcResourceValues {
public:
ProcResourceValues(int x, int y, int z) { }
};
class ResourceCalculator {
public:
ProcResourceValues data;
ProcResourceValues& emptyProcResourceValues();
ProcResourceValues& emptyProcResourceValuesIHatePascalMixedCase();
};
ProcResourceValues& ResourceCalculator::emptyProcResourceValues() {
return *(new ProcResourceValues(0,0,0));
}
ProcResourceValues& ResourceCalculator::emptyProcResourceValuesIHatePascalMixedCase() {
return data;
}
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.